VBNET中的XML解析 [英] XML PARSING in VBNET
本文介绍了VBNET中的XML解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在VBNET中创建一个程序,该程序允许我解析xmlfile,然后列出所有元素,并逐行计数个元素.
我的xmlfile看起来像这样:
I''m trying to make a program in VBNET which allows me to parse an xmlfile, then lists all the elements and counts the elements line by line.
My xmlfile looks like this :
<?xml version="1.0" encoding="ISO-8859-1" ?>
- <flexdump>
- <FLXREC1001>
<ID>1</ID>
<PTY002>SIREUS nv</PTY002>
<PTY004>F. Rooseveltlaan 349</PTY004>
<PTY005>10</PTY005>
<PTY008>9000</PTY008>
<PTY009>GENT</PTY009>
<PTY020>09/211.02.21</PTY020>
<PTY022>Support : 9.00 - 12.00</PTY022>
<PTY023>09/211.02.22</PTY023>
<PTY025>BE 0437.034.587</PTY025>
<PTY030>support@sireus.net</PTY030>
<PTY031>0</PTY031>
<PTY032>2</PTY032>
<PTY034>3</PTY034>
<PTY038>Mijne Heren,</PTY038>
<PTY039>03</PTY039>
<PTY040>L</PTY040>
<PTY045>5</PTY045>
<PTY061>BE33 8805 3016 3146</PTY061>
</FLXREC1001>
有什么简单的想法吗?
thx
Giet
Any (simple) ideas ?
thx
Giet
推荐答案
使用 XDocument 类非常简单.阅读并在线查看示例.这应该是一个好的开始. http://msdn.microsoft.com/en-us/library/system. xml.linq.xdocument.aspx [ ^ ]
It is incredibly simple to do using the XDocument class. Give it a read and check out examples online. This should be a good start. http://msdn.microsoft.com/en-us/library/system.xml.linq.xdocument.aspx[^]
XML解析在.NET中很好地实现.我在下面概述了至少三个不同的选项:
XML parsing is well implemented in .NET. You have at least three different options I overview below:
- 使用
System.Xml.XmlDocument
类.它实现了DOM接口;如果文档太大,则这种方法最简单,也足够好.
请参见- 使用类
].System.Xml.XmlTextReader
; library/system.xml.xmldocument.aspx"target =" _ blank"title =" New Window> ^ - 使用类
- 使用类
System.Xml.XmlTextReader
;这是最快的读取方法,尤其是您需要跳过一些数据.
请参见 http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx [ http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx [http://msdn.microsoft.com/en-us/library/bb387063.aspx [
- Use
System.Xml.XmlDocument
class. It implements DOM interface; this way is the easiest and good enough if the size if the document is not too big.
See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^]. - Use the class
System.Xml.XmlTextReader
; this is the fastest way of reading, especially is you need to skip some data.
See http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx[^]. - Use the class
System.Xml.Linq.XDocument
; this is the most adequate way similar to that ofXmlDocument
, supporting LINQ to XML Programming.
See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^], http://msdn.microsoft.com/en-us/library/bb387063.aspx[^].
这篇关于VBNET中的XML解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文