Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Pars this xml sample using vb.net

Posted on 2009-05-05
7
Medium Priority
?
524 Views
Last Modified: 2013-11-11
Fairly new to this process and I need to parse this xml file. Any assistance would be great. I can iterate through each element and grab the data pertaining to it.  Below is the code I have, unfortunately I need to do a few more things such as grabbing the customer id(s) etc.
Dim doc As XmlDocument = New XmlDocument
        doc.Load("C:\XML\2209_SIC_Claims_Extract_Inception_to_Date_March2009.xml")
        Dim m_xmld As XmlDocument
        Dim m_nodelist As XmlNodeList
        Dim m_node As XmlNode
        'Create the XML Document
        m_xmld = New XmlDocument()
        'Load the Xml file
        m_xmld.Load("C:\XML\2209_SIC_Claims_Extract_Inception_to_Date_March2009.xml")
        'Get the list of nodes 
        m_nodelist = m_xmld.SelectNodes("//LossRunInquiryResult")
        'Loop through the nodes
        Dim Count As Integer
        Dim VariableName As String
        Dim VariableValue As String
        Dim nvCollection As New System.Collections.Specialized.NameValueCollection
        For Each m_node In m_nodelist
            For i As Integer = 0 To m_node.ChildNodes.Count - 1
                VariableName = m_node.ChildNodes.Item(i).Name
                VariableValue = m_node.ChildNodes.Item(i).InnerText
                Console.Write(VariableName & ":" & VariableValue)
                Console.Write(vbCrLf)
                Count += 1
                nvCollection.Add(VariableName, VariableValue)
            Next
        Next

Open in new window

2209-SIC-Claims-Extract-Inceptio.txt
0
Comment
Question by:E-Risk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
7 Comments
 
LVL 39

Expert Comment

by:abel
ID: 24310328
I'm not really understand the part where you say "etc"... Do you want more help with the loop to walk the DOM or do you want more help to dig up some SelectNodes XPaths that can give you the information you need? In both cases, I would like to know what "etc" is about ;)

also, I don't see any customer ids in the XML source. What is a customer id?


0
 
LVL 2

Author Comment

by:E-Risk
ID: 24314528
Sorry for not clarifying. Yes I would like to use SelectNodes XPaths that can give me the information I need. As for the customer number I meant ClaimNumber as an example. I am assuming I need to get the ID attribute in order to get these details for the claimnumber. Seems there are varying node types through out the xml file. How would I determine in the loop the node type and grab any details? My ultimate goal is to get the details in the XML file into a database table.

Thanks for your help here and hopefully this is clearer now.
0
 
LVL 39

Accepted Solution

by:
abel earned 2000 total points
ID: 24341127
If you want to loop through certain nodes and then process the child nodes of those nodes, it is usually best to use a SelectNodes from that child node, which will give you easier control over the objects you are searching.

For Each m_node As XmlNode In m_nodelist
    For Each newNode As XmlNode in m_node.SelectNodes("relative/path/to/node")
    ....

note that this can quickly become very nested. To prevent that, it is usually a good idea to create some functions for the inner nodes that you want to process, but that is a matter of taste.

There are many ways of processing an XML document and I am not sure if this method is the best for you. If you want to change the xml document into another document, XSLT should be chosen. If you want to process it sequentially, XmlTextReader should be used (but be aware, it is tricky and forward-only). More complex processing can be done with XPaths.

An important thing to know when working with DOM and nodes is: they are never disconnected from the rootnode. That means, you can do something like


For Each m_node As XmlNode  In m_nodelist
     id = SelectNodes("../../@id")(0).Value

to get the id attribute of a parent node.

To get information about any node, you can use the .Value, .Name, .LocalName and the many other methods and properties that an XmlNode has.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:E-Risk
ID: 24353918
Thanks Abel,
I will give this a try and let you know how it works. I agree this can be tricky but hopefully this steers me in the correct direction. Thanks
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24522235
0
 
LVL 39

Expert Comment

by:abel
ID: 24730905
I believe my answer in http:#24341127 quite well steers the asker in the right direction. (s)He said to check back after trying. No news is good news?
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question