我有一个像这样的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
通过这种方法我只添加了新节点但没有属性,我该如何设置该节点的属性?
答案 0 :(得分: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