如何将子节点附加到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