+ -
当前位置:首页 → 问答吧 → VB删除XML节点

VB删除XML节点

时间:2007-05-18

来源:互联网

<Dongbin>
      <Papers>
            <Paper   Top= "1300 "   Left= "500 "   Width= "22002 "   Height= "29336 "> A3 </Paper>
            <Paper   Top= "1300 "   Left= "500 "   Width= "11001 "   Height= "14668 "> A4 </Paper>
            <Paper   Top= "1000 "   Left= "450 "   Width= "8001 "   Height= "10668 "> A5 </Paper>
            <Paper   Top= "4200 "   Left= "400 "   Width= "5400 "   Height= "7200 "> A6 </Paper>
            <Paper   Top= "7000 "   Left= "300 "   Width= "3300 "   Height= "4400 "> Card </Paper>
      </Papers>
      <Layouts>
            <!--fgds-->

            <Layout   Pic= "\Layout\001.jpg ">
                  <Sub   Top= "0 "   Left= "0 "   Width= "1200 "   Height= "1600 "/>
            </Layout>

            <Layout   Pic= "\Layout\002.jpg ">
                  <Sub   Top= "0 "   Left= "75 "   Width= "1055 "   Height= "790 "   />
                  <Sub   Top= "810 "   Left= "75 "   Width= "1055 "   Height= "790 "/>
            </Layout>

</Layouts>

XML如上

用VB删除第一个layout节点

Dim   xmlDoc   As   DOMDocument
Dim   xmleml   As   IXMLDOMElement
Dim   xn   As   IXMLDOMNode
Dim   xnl   As   IXMLDOMNodeList
Set   xmlDoc   =   New   DOMDocument

      xmlDoc.Load   (App.Path   &   "\Layout\Layout.xml ")
     
        If   xmlDoc.documentElement   Is   Nothing   Then
                        Exit   Function
        End   If


xn   =   xmlDoc.selectSingleNode( "/Layouts/Layout[@Pic= '\Layout\001.jpg '] ")
上面这句   错误提示   实时错误91,对象变量或with变量未设置!

xmlDoc.parentNode.removeChild   (xn)


请问该如何解决或者实现删除
<Layout   Pic= "\Layout\001.jpg ">
                  <Sub   Top= "0 "   Left= "0 "   Width= "1200 "   Height= "1600 "/>
          </Layout>

作者: windrey   发布时间: 2007-05-18

没人回啊?问题没给分/。谁作答了给最少50分!

作者: windrey   发布时间: 2007-05-18

xn = xmlDoc.selectSingleNode( "/Layouts/Layout[@Pic= '\Layout\001.jpg '] ") 
这句中selectSingleNode好像不支持\Layout\001.jpg 这种带斜杠的。

也许可以用
xn = xmlDoc.selectSingleNode("Dongbin/Layouts/Layout/Sub[@Left='0']")

xn.parentNode.removeChild(xn) 

作者: linxtong   发布时间: 2011-09-07