如何将 xml 字符串读入 XMLTextReader 类型

2024-01-30

我有一个 XML 字符串。我需要将此字符串转换为XML文本阅读器(System.Xml.XMLTextReader) 输入 dotnet。

我使用了以下代码:

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

但是里面的字符串reader执行后为空。

请帮助我弄清楚需要做什么才能让 XMLTextReader 填充给定的字符串。


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

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

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何将 xml 字符串读入 XMLTextReader 类型 的相关文章

随机推荐