创建 System.Xml.XmlDocument,而不是从字符串创建
是否可以通过解析字符串来创建 System.Xml.XmlDocument 而不进行初始化?
我想创建一个表示 XML
的 XmlDocument
我知道初始化 XmlDocument 的正常方法是通过字符串解析,如下所示:
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.LoadXml("<rootEl />");
但是,是否可以使用下面概述的方法?
System.Xml.XmlDocument doc = new System.Xml.XmlDocument("rootEl");
(我知道 System.Xml.Linq 似乎更灵活,但现在我仍坚持旧学校。)
It is possible to create a System.Xml.XmlDocument without initializing by parsing a string?
I want to create a XmlDocument representing the XML <rootEl />
I known the normal way to initialize an XmlDocument is by string-parsing as below:
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.LoadXml("<rootEl />");
However, is it possible to use the method outlined below?
System.Xml.XmlDocument doc = new System.Xml.XmlDocument("rootEl");
(I understand System.Xml.Linq seems to be more flexible, but right now I am stuck with oldschool.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯,不可能完全使用您提供的代码来完成此操作。
XmlDocument
它将内容作为流或字符串。另一方面,你可以写:
这是你想要的吗?请更具体地说明您想要实现的目标。
Well, it's not possible to do it with exactly the code you've given. There's no constructor for
XmlDocument
which takes the content, either as a stream or as a string.On the other hand, you could write:
Is that what you want? Please be more specific about what you're trying to achieve.
我认为你不能按照你想要的方式去做。
不确定这是否是您所需要的,但您可以这样做:
I think you can't do it the way you want.
Not sure if this is what you need, but you could do it like this: