22

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.

4

1 回答 1

43

如何判断字符串是否为空?

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

如果没有第三行,“内部”确实是空的。现在它包含测试。

于 2011-01-05T07:53:59.450 回答