views:

539

answers:

1
<%
    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>
+4  A: 

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
Shog9