简体   繁体   中英

Read XML Node in VB.NET

I'm writing an assembly in VB.NET which will connect to a rest web service, call the contents in XML and upon being returned I want to specifically grab the contents and write it to a file. I'm new at this and looking to get the contents of the column1 node and write it into a text file.

The XML looks like this:

<p5:test xmlns:p5="http://www.myapp.com/database/test">
<row>
<column1>test</column1>
</row>
<row>
<column1>Test2</column1>
</row>
</p5:test>

Can anyone provide an example of how I may do so?

Thanks!

Try it.Hope that is helps.

Dim xmldoc As New XmlDataDocument()
            Dim xmlnode As XmlNodeList
            Dim i As Integer
            Dim str As String
            Dim fs As New FileStream("YourFileName.xml", FileMode.Open, FileAccess.Read)
            xmldoc.Load(fs)
            xmlnode = xmldoc.GetElementsByTagName("column1")
            For i = 0 To xmlnode.Count - 1
                xmlnode(i).ChildNodes.Item(0).InnerText.Trim()
                str += xmlnode(i).ChildNodes.Item(0).InnerText.Trim() 
    Next

    System.IO.File.WriteAllLines(@"C:\Users\Public\TestFolder\WriteLines.txt", str);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM