gpt4 book ai didi

c# - 'XmlDocument.CreateElement();' 只创建一个元素吗?

转载 作者:太空宇宙 更新时间:2023-11-03 22:47:36 25 4
gpt4 key购买 nike

好像someXml.CreateElement("abc");只做一件事:创建元素。它没有像我预期的那样将它添加为 child ,似乎也没有做任何其他事情。

但这没有多大意义。为什么使用实例方法而不是静态方法创建元素?这将表明它确实与实例有某种关系。但我找不到任何东西,因此我的问题。

最佳答案

Microsoft 文档中的备注提到在返回的对象上创建默认属性。命名空间会浮现在脑海中,因为它们可能会根据 XmlDocument 的架构/默认值自动应用于新元素。

它还声明必须手动将其添加到所需的父节点。

来自 https://msdn.microsoft.com/en-us/library/fw1ys7w6(v=vs.110).aspx

Note that the instance returned implements the XmlElement interface, so default attributes would be created directly on the returned object.

Although this method creates the new object in the context of the document, it does not automatically add the new object to the document tree. To add the new object, you must explicitly call one of the node insert methods.

关于c# - 'XmlDocument.CreateElement();' 只创建一个元素吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49159558/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com