2016-07-27 17 views
1

i vb verwenden, und ich bin Laden den xml auf diese WeiseEntfernen Knoten aus XML-doc in vb

xml_doc.LoadXml(contents) 

Nun ich einen Knoten aus dieser geladenen XML entfernen möge oder von Inhalten (dies gilt Ganze xml), ich bin mir nicht sicher, wo es sein muss. Die XML ist wie folgt

<?xml version="1.0" standalone="yes"?> 
 
<sdnList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/sdnList.xsd"> 
 
    <publshInformation> 
 
    <Publish_Date>07/21/2016</Publish_Date> 
 
    <Record_Count>5393</Record_Count> 
 
    </publshInformation> 
 
    <sdnEntry> 
 
    <uid>36</uid> 
 
    </sdnEntry> 
 
</sdnList>

Was möchte ich tun, ist, diesen Tag und alle sollten in

<publshInformation>......</publshInformation> 
+0

Können Sie das Problem mit meiner Antwort zu lösen, wie es LINQ nicht braucht? – DAXaholic

+0

ja deine antwort hat mir geholfen danke :) –

Antwort

1

Sie in der Lage zu entfernen, um es zu entfernen, wie so

Dim nodeToRemove as XmlNode = xml_doc.SelectSingleNode("//*[local-name()='publshInformation']") 
nodeToRemove.ParentNode.RemoveChild(nodeToRemove) 

Hinweis: Ich habeverwendetim XPath, um den XML-Namespace zu ignorieren.

0

Verwendung von XML Linq:

Imports System.Xml 
Imports System.Xml.Linq 
Module Module1 
    Const FILENAME As String = "c:\temp\test.xml" 
    Sub Main() 
     Dim doc As XDocument = XDocument.Load(FILENAME) 
     Dim publshInformation As XElement = doc.Descendants().Where(Function(x) x.Name.LocalName = "publshInformation").FirstOrDefault() 
     publshInformation.Remove() 
    End Sub 

End Module 
+0

ich bin auf ältere version, coz das ist grosses altes projekt (vs2003), kann nicht Linq benutzen –