1

我有一个这样的 xml 架构:

<?xml version="1.0" encoding="utf-8"?>
<NEWS>
       <category title="title">
              <sbml title="title" value="SBML_NEWSBGCOLOR" version="7.26.23" />
              <sbml title="title" value="SBML_NEWSWIDTHTYPE" version="7.26.23" />
       </category>
</NEWS>

我正在使用 asp Classic,并且我有一个传递 4 个变量来创建新<sbml />节点的表单。

Set objXML = Server.CreateObject("MSXML2.DOMDocument.3.0")
objXML.async = False
objXML.setProperty "ServerHTTPRequest", True
strXMLFile = Server.MapPath("\") & "\admin\sbml\72623.xml"
if objXML.Load(strXMLFile) Then
       If Request.ServerVariables("REQUEST_METHOD")="POST" Then
              Set new_sbml = objXML.createElement("sbml")
              objXML.selectSingleNode(noInj(rq("M")) & "/category").appendChild(new_sbml)
              objXML.save strXMLFile
       End if
End if

通过这种方法,我只是添加了新节点但没有属性,如何设置该节点的属性?

4

1 回答 1

2

我刚刚找到我的答案

Set objXML = Server.CreateObject("MSXML2.DOMDocument.3.0")
objXML.async = False
objXML.setProperty "ServerHTTPRequest", True
strXMLFile = Server.MapPath("\") & "\admin\sbml\72623.xml"
if objXML.Load(strXMLFile) Then
       If Request.ServerVariables("REQUEST_METHOD")="POST" Then
              Set new_sbml = objXML.createElement("sbml")
              new_sbml.setAttribute "title", new_title 'Here i set attribute
              objXML.selectSingleNode("/category").appendChild(new_sbml)
              objXML.save strXMLFile
       End if
End if
于 2012-04-08T14:30:48.097 回答