如何将子节点附加到DOM对象中的元素? [英] How can I append a child node to an element in a DOM object?

查看:131
本文介绍了如何将子节点附加到DOM对象中的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<%
    Set xmlDoc = Server.CreateObject("MSXML2.DOMDOCUMENT")
    xmlDoc.loadXML( "<response />" )

    Set node = xmlDoc.createElement("account")
    xmlDoc.documentElement.AppendChild node

    Set node = xmlDoc.createElement("type")
    node.Text = "TheType"
    xmlDoc.documentElement.AppendChild node

    Set node = Nothing
%>

这将创建一个如下所示的XML文档:

This creates an XML doc that looks like the following:

   <response>
        <account></account>
        <type>TheType</type>
   </response>

如何将类型节点作为子节点附加到newaccount节点,以便它看起来像这样:

How do I append the "type" node as a child node to the "newaccount" node so that it looks like this:

   <response>
        <account>
            <type>TheType</type>
        </account>
   </response>


推荐答案

同样的方式,你将它附加到文档元素现在:

Same way you're appending it to the document element now:

Set accountEl = xmlDoc.createElement("account")
xmlDoc.documentElement.AppendChild accountEl

Set typeEl = xmlDoc.createElement("type")
typeEl.Text = "TheType"
accountEl.AppendChild typeEl

accountEl = Nothing
typeEl = Nothing

这篇关于如何将子节点附加到DOM对象中的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆