将节点字符串解析为 XMLNodeList
我很好奇,将 xml 节点字符串解析为 XmlNodeList 的最简洁方法是什么。例如;
string xmlnodestr = "<mynode value1='1' value2='123'>abc</mynode>
<mynode value1='1' value2='123'>abc</mynode>
<mynode value1='1' value2='123'>abc</mynode>";
我可以在列表上进行字符串拆分,但这会很混乱且不正确。
理想情况下,我想要类似的东西;
XmlNodeList xmlnodelist = xmlnodestr.ParseToXmlNodeList();
I'm curious, what would be the neatest way to parse a string of xml nodes to a XmlNodeList. For example;
string xmlnodestr = "<mynode value1='1' value2='123'>abc</mynode>
<mynode value1='1' value2='123'>abc</mynode>
<mynode value1='1' value2='123'>abc</mynode>";
I could possibly do a string split on the list, but that would be messy and non-proper.
Ideally I want something like;
XmlNodeList xmlnodelist = xmlnodestr.ParseToXmlNodeList();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以向 XML 添加根,然后使用此方法:
如果您可以使用 LINQ to XML,这会简单得多,但您不会使用
XmlNodeList
:You could add a root to your XML then use this approach:
If you can use LINQ to XML this would be much simpler, but you wouldn't be working with an
XmlNodeList
:下面是一个使用
XmlDocumentFragment
执行此操作的示例程序,并在 .NET 2.0 中进行了测试:它产生以下输出:
Here's a sample program that does it using an
XmlDocumentFragment
, tested in .NET 2.0:It produces the following output: