Click here to Skip to main content
15,030,240 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
<?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>


Any (simple) ideas ?

thx

Giet
Posted

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[^]
   
Comments
Sergey Alexandrovich Kryukov 20-Mar-12 14:10pm
   
This is just one possibility (I voted 4). There are more options; XmlDocument (DOM-based) could be even easier, especially for small XMLs. Please see my answer.
--SA
XML parsing is well implemented in .NET. You have at least three different options I overview below:


  1. 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[^].
  2. 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[^].
  3. Use the class System.Xml.Linq.XDocument; this is the most adequate way similar to that of XmlDocument, 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[^].


—SA
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900