一個簡單的問題--如何用javascript增加xml?

888yyf888 2004-12-17 04:10:51
如何用javascript增加xml?
...全文
115 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
rainxiang 2004-12-17
  • 打赏
  • 举报
回复
<script>
x = new ActiveXObject("Msxml2.DOMDocument")
x.loadXML("<Record><Elm_1><Elm_3>null</Elm_3></Elm_1><Elm_2><Elm_4>null</Elm_4><Elm_5><Elm_6>null</Elm_6></Elm_5></Elm_2></Record>")
alert(x.xml)
x3=x.selectSingleNode("/Record/Elm_1/Elm_3")

x3new = x.createElement("Xa")
x3new.text="333"
x3.appendChild(x3new)
alert(x.xml)

x6=x.selectSingleNode("//Elm_6")

x6new = x.createElement("Xa")
x6new.text="666"
x6.appendChild(x6new)
alert(x.xml)

xid=x.selectSingleNode("//Elm_1")

xidnew = x.createAttribute("id")
xidnew.value="iddddddd"

xid.attributes.setNamedItem(xidnew)
alert(x.xml)

xid=x.selectSingleNode("//Elm_1/@id")
xidnew.value="idddddddnewnewnewnewnewnewnewnewnewnewnew"
alert(x.xml)

xid=x.selectSingleNode("//Elm_4")
xid.text="新内容"
alert(x.xml)

xid=x.selectSingleNode("//Elm_1")
xid.parentNode.removeChild(xid)
alert(x.xml)

</script>

8,906

社区成员

发帖
与我相关
我的任务
社区描述
XML/XSL相关问题讨论专区
社区管理员
  • XML/XSL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧