将 XmlDocument 插入 XmlDocument 节点

发布于 2024-09-26 11:31:47 字数 411 浏览 1 评论 0原文

我使用一个节点创建了一个基本 XmlDocument:

XmlDocument bigDoc = new XmlDocument();
bigDoc.LoadXml("<Request></Request>");

并且我得到了另一个要插入到 节点内的 XmlDocument。 它对我不起作用:

 XmlNode requestNode =  bigDoc.FirstChild;
 requestNode.AppendChild(anotherXMLDocument);

它抛出一个异常。

如何在另一个 XmlDocument 节点中插入 XmlDocument?

I created a basic XmlDocument with one node:

XmlDocument bigDoc = new XmlDocument();
bigDoc.LoadXml("<Request></Request>");

and I'm getting another XmlDocument that I want to insert inside <Request> node.
It doesn't work for me:

 XmlNode requestNode =  bigDoc.FirstChild;
 requestNode.AppendChild(anotherXMLDocument);

It thorows an exception.

How can I insert a XmlDocument inside another XmlDocument node?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

静待花开 2024-10-03 11:31:47

如果我没记错的话,在每个 DOM 实现(.net、javascript、php 等)中它基本上都是相同的。这应该可以工作

XmlNode requestNode =  bigDoc.FirstChild;
requestNode.AppendChild(
    requestNode.OwnerDocument.ImportNode(
        anotherXMLDocument.DocumentElement, true));

。true(importNode 的第二个参数)应该意味着导入深度。

If I recall correctly that it's basically the same thing in every DOM Implementation around (.net, javascript, php etc. this should work.

XmlNode requestNode =  bigDoc.FirstChild;
requestNode.AppendChild(
    requestNode.OwnerDocument.ImportNode(
        anotherXMLDocument.DocumentElement, true));

The true (2nd argument to importNode) should mean import deep.

匿名。 2024-10-03 11:31:47
Public Sub rutina(ByRef Sobre As String, ByVal Cfe As String)
    'Agrega CFE al final de sobre, que puede ya contener
    'otro(s) CFE

    'Abre el sobre.
    Dim doc As New XmlDocument()
    doc.Load(Sobre)

    'Abre el xml con el nuevo CFE
    Dim doc2 As New XmlDocument()
    doc2.Load(Cfe)

    'Importa el CFE al final del sobre (antes de </Fin> )
    Dim newBook As XmlNode = doc.ImportNode(doc2.DocumentElement, True)
    doc.DocumentElement.AppendChild(newBook)

    doc.Save(Sobre)
End sub
Public Sub rutina(ByRef Sobre As String, ByVal Cfe As String)
    'Agrega CFE al final de sobre, que puede ya contener
    'otro(s) CFE

    'Abre el sobre.
    Dim doc As New XmlDocument()
    doc.Load(Sobre)

    'Abre el xml con el nuevo CFE
    Dim doc2 As New XmlDocument()
    doc2.Load(Cfe)

    'Importa el CFE al final del sobre (antes de </Fin> )
    Dim newBook As XmlNode = doc.ImportNode(doc2.DocumentElement, True)
    doc.DocumentElement.AppendChild(newBook)

    doc.Save(Sobre)
End sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文