How to read a xml string into XMLTextReader type

六眼飞鱼酱① 提交于 2019-12-03 11:14:59

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/4601139/how-to-read-a-xml-string-into-xmltextreader-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!