Как я могу добавить дочерний узел к элементу в объекте DOM? - PullRequest
1 голос
/ 12 ноября 2008
<%
    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, который выглядит следующим образом:

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

Как добавить узел типа в качестве дочернего узла к узлу newaccount, чтобы он выглядел так:

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

1 Ответ

4 голосов
/ 12 ноября 2008

Так же, как вы сейчас добавляете его к элементу документа:

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

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

accountEl = Nothing
typeEl = Nothing
...