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

这将创建一个如下所示的 XML 文档:

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

如何将“type”节点作为子节点附加到“newaccount”节点,使其看起来像这样:

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

1 回答 1

4

与您现在将其附加到文档元素的方式相同:

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

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

accountEl = Nothing
typeEl = Nothing
于 2008-11-12T15:36:59.127 回答