How can I append a child node to an element in a D

2019-07-25 18:44发布

<%
    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
%>

This creates an XML doc that looks like the following:

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

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>

1条回答
Explosion°爆炸
2楼-- · 2019-07-25 19:23

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
查看更多
登录 后发表回答