[英]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. 我正在VB.NET中编写一个程序集,该程序集将连接到其余的Web服务,以XML调用内容,返回后,我要专门抓取内容并将其写入文件。 I'm new at this and looking to get the contents of the column1 node and write it into a text file.
我是新来的,希望获取column1节点的内容并将其写入文本文件。
The XML looks like this: XML如下所示:
<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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.