Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read a xml string into XMLTextReader type

Tags:

I have an XML string. I need to convert this string into XMLTextReader(System.Xml.XMLTextReader) type in dotnet.

I used the following code:

string szInputXml = "<TestDataXml><DataName>testing</DataName></TestDataXml>" ; XmlTextReader reader = new XmlTextReader(new System.IO.StringReader(szInputXml)); 

But the string inside the reader is empty after execution.

Please help me to figure out what needs to be done to get the XMLTextReader to be populated with the given string.

like image 224
osum Avatar asked Jan 05 '11 05:01

osum


1 Answers

How do you determine if the string is empty?

string szInputXml = "<TestDataXml><DataName>testing</DataName></TestDataXml>"; XmlTextReader reader = new XmlTextReader( new System.IO.StringReader( szInputXml ) ); reader.Read(); string inner = reader.ReadInnerXml(); 

Without 3rd line "inner" was empty indeed. Now it contains testing.

like image 115
dzendras Avatar answered Oct 16 '22 11:10

dzendras