How do I add a child node to an element of a DOM object?

<%
    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 document that looks like this:

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

      

How do I add 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


source to share


1 answer


Likewise, you add it to the document element:



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

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

accountEl = Nothing
typeEl = Nothing

      

+4


source







All Articles