xml vb.net:如何删除第二个孩子? [英] xml vb.net : how to delete second child?

查看:74
本文介绍了xml vb.net:如何删除第二个孩子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个xml:

 <   un:casamae     Id   =  1 >  
< un:casafilha Id = 1 >
< xn:telhado < span class =code-attribute> id = 没有记录 >
< / xn:telhado >
< xn:telhado id = 没有记录 修饰符 = 创建 >
< xn:composicao >
< xn:tipotelha > vermelho < / xn:vsDataType >
< xn:numerotelhas > 127 < / xn:vsDataFormatVersion >
< es:vermelho < span class =code-keyword> / >
< / xn:composicao >
< / xn:telhado >
< xn:muro id = 256 修饰符 = 创建 >
< / xn:muro >
< / un:casafilha >
< un:casafilha Id = 65501 >
< / un:casafilha >





我想要这个:



< pre lang =xml> < un:casamae Id = 1 >
< un:casafilha Id = < span class =code-keyword> 1 >
< xn:muro id = 256 修饰符 = 创建 >
< / xn:muro >
< / un:casafilha >
< un:casafilha Id = 65501 >
< / un :casafilha >





这是代码我到目前为止:

 doc2.Load(folder_dest& \ xpto.xml)
For casafilha in casafihalist
Dim xpathstring2 =un:casamae // un:casafilha [@ Id =& casafilha& ]
Dim nodeselect2 As XmlNode = doc2.SelectSingleNode(xpathstring2,namespaces)
For Each node As XmlNode in nodeselect2.SelectNodes(// xn:telhado [@id =''without records'' ],名称空间)
node.ParentNode.RemoveChild(node)
下一页
下一页casafilha
doc2.Save(folder_dest&\ xptox)





问题:

我尝试了几种解决方案,但到目前为止,我只是能够删除带有id属性的第一个chid xml等于没有记录,总是留下id =without records和modifier =create的那个。



如何删除任何类型的telhado id =没有记录及其自己的子元素?

解决方案





 doc2.SelectSingleNode 





您选择的是单个节点。



必须使用此功能 http://msdn.microsoft.com/en-us /library/system.xml.xmlnode.selectnodes.aspx [ ^ ]接收节点列表。



祝你好运!

JAFC


doc2.Load(folder_dest&\ xptox)



Dim nodeselect2作为XmlNodelist



nodeselect2 = doc2.SelectNodes(// xn:telhado [@id =''没有记录''],命名空间)



For Each node As XmlNode In nodeselect2



doc2.RemoveChild(node)



下一页



doc2.Save(folder_dest&\ xptox)


I have this xml :

<un:casamae Id="1">
           <un:casafilha Id="1">
            <xn:telhado id="without records">
           </xn:telhado>
                <xn:telhado id="without records" modifier="create">
               <xn:composicao>
                 <xn:tipotelha>vermelho</xn:vsDataType>
                 <xn:numerotelhas>127</xn:vsDataFormatVersion>
                 <es:vermelho />
               </xn:composicao>
             </xn:telhado>
                <xn:muro id=256 modifier="create">
                </xn:muro>
           </un:casafilha>
           <un:casafilha Id="65501">
           </un:casafilha>



I want this :

<un:casamae Id="1">
           <un:casafilha Id="1">
                <xn:muro id=256 modifier="create">
                </xn:muro>
           </un:casafilha>
           <un:casafilha Id="65501">
           </un:casafilha>



This is the code I have so far:

doc2.Load(folder_dest & "\xpto.xml")
           For Each casafilha In casafihalist
               Dim xpathstring2 = "un:casamae//un:casafilha[@Id=" & casafilha & "]"
               Dim nodeselect2 As XmlNode = doc2.SelectSingleNode(xpathstring2, namespaces)
               For Each node As XmlNode In nodeselect2.SelectNodes("//xn:telhado[@id=''without records'']", namespaces)
                   node.ParentNode.RemoveChild(node)
               Next
           Next casafilha
           doc2.Save(folder_dest & "\xpto.xml")



The problem:
I''ve tried several solutions, but so far, I just being able of deleting the first chid xml with the "id" atribute equals "without records", leaving always the one with the id="without records" and modifier="create" behind.

How can I delete any kind of telhado id="without records" and their own subelements?

解决方案

Hi,

doc2.SelectSingleNode



You''re selecting a single node.

Must use this function http://msdn.microsoft.com/en-us/library/system.xml.xmlnode.selectnodes.aspx[^] to receive a list of nodes.

Good luck!
JAFC


doc2.Load(folder_dest & "\xpto.xml")

Dim nodeselect2 As XmlNodelist

nodeselect2=doc2.SelectNodes("//xn:telhado[@id=''without records'']", namespaces)

For Each node As XmlNode In nodeselect2

doc2.RemoveChild(node)

Next

doc2.Save(folder_dest & "\xpto.xml")


这篇关于xml vb.net:如何删除第二个孩子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆