MSXML向文件中添加节点
展开全部
<?xml version="1.0"?>
<BBS>
<topic topicId="0">
<title>this web site is good</title>
<time> 2005-09-08 08:00:00</time>
<ip>221.106.82.*</ip>
<body>when I was young</body>
<nickname>Anonymous</nickname>
<replies>
<reply replyID="0">
<title>this web site is good</title>
<time> 2005-09-08 08:00:00</time>
<ip>221.106.82.*</ip>
<body>when I was young</body>
<nickname>Anonymous</nickname>
</reply>
<reply replyId="1">
<title>111</title>
<time>09-13-2005 11:37:25GMT</time>
<ip>127.0.0.*</ip>
<body>1111</body>
<nickname>111</nickname>
</reply>
</replies>
</topic>
<topic topicId="1">
<title>this web site look good</title>
<time> 2005-09-08 06:00:00</time>
<ip>66.106.82.*</ip>
<body>luck off product</body>
<nickname>Anonymous</nickname>
</topic>
</BBS>
以上是XML文件
以下是ASP
<%
Set objNode = objXML.getElementsByTagName("BBS/topic/replies")
Set objNode = objNode.Item(0)
Set replyInfoNode = objXML.createNode("element", "reply", "")
Set replyInfoNode = objNode.appendChild(replyInfoNode)
Set replyIdInfo = objXML.createAttribute("replyId")
replyIdInfo.Text = replyID
replyInfoNode.Attributes.setNamedItem (replyIdInfo)
Set replyIdNode = objXML.createNode("element", "title", "")
replyIdNode.Text = title
Set replyIdNode = replyInfoNode.appendChild(replyIdNode)
Set replyIdNode = objXML.createNode("element", "time", "")
replyIdNode.Text = content_time
Set replyIdNode = replyInfoNode.appendChild(replyIdNode)
Set replyIdNode = objXML.createNode("element", "ip", "")
replyIdNode.Text = ip
Set replyIdNode = replyInfoNode.appendChild(replyIdNode)
Set replyIdNode = objXML.createNode("element", "body", "")
replyIdNode.Text = content
Set replyIdNode = replyInfoNode.appendChild(replyIdNode)
Set replyIdNode = objXML.createNode("element", "nickname", "")
replyIdNode.Text = nickname
Set replyIdNode = replyInfoNode.appendChild(replyIdNode)
objXML.save (Server.MapPath("bbs.xml"))
response.redirect "showlist.asp"
%>
<BBS>
<topic topicId="0">
<title>this web site is good</title>
<time> 2005-09-08 08:00:00</time>
<ip>221.106.82.*</ip>
<body>when I was young</body>
<nickname>Anonymous</nickname>
<replies>
<reply replyID="0">
<title>this web site is good</title>
<time> 2005-09-08 08:00:00</time>
<ip>221.106.82.*</ip>
<body>when I was young</body>
<nickname>Anonymous</nickname>
</reply>
<reply replyId="1">
<title>111</title>
<time>09-13-2005 11:37:25GMT</time>
<ip>127.0.0.*</ip>
<body>1111</body>
<nickname>111</nickname>
</reply>
</replies>
</topic>
<topic topicId="1">
<title>this web site look good</title>
<time> 2005-09-08 06:00:00</time>
<ip>66.106.82.*</ip>
<body>luck off product</body>
<nickname>Anonymous</nickname>
</topic>
</BBS>
以上是XML文件
以下是ASP
<%
Set objNode = objXML.getElementsByTagName("BBS/topic/replies")
Set objNode = objNode.Item(0)
Set replyInfoNode = objXML.createNode("element", "reply", "")
Set replyInfoNode = objNode.appendChild(replyInfoNode)
Set replyIdInfo = objXML.createAttribute("replyId")
replyIdInfo.Text = replyID
replyInfoNode.Attributes.setNamedItem (replyIdInfo)
Set replyIdNode = objXML.createNode("element", "title", "")
replyIdNode.Text = title
Set replyIdNode = replyInfoNode.appendChild(replyIdNode)
Set replyIdNode = objXML.createNode("element", "time", "")
replyIdNode.Text = content_time
Set replyIdNode = replyInfoNode.appendChild(replyIdNode)
Set replyIdNode = objXML.createNode("element", "ip", "")
replyIdNode.Text = ip
Set replyIdNode = replyInfoNode.appendChild(replyIdNode)
Set replyIdNode = objXML.createNode("element", "body", "")
replyIdNode.Text = content
Set replyIdNode = replyInfoNode.appendChild(replyIdNode)
Set replyIdNode = objXML.createNode("element", "nickname", "")
replyIdNode.Text = nickname
Set replyIdNode = replyInfoNode.appendChild(replyIdNode)
objXML.save (Server.MapPath("bbs.xml"))
response.redirect "showlist.asp"
%>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询