Solved

Help with accessing nodes of an xml file

Posted on 2014-07-28
3
113 Views
Last Modified: 2014-10-20
I have  an xml Which I receive from a web service in the usual format. the structure of the XML is as below

<DataDS>
<tab>
<col1>val1</col1>
<col2>val2</col2>
<col3>val3</col3>
<col4>val4</col4>
<col5>val5</col5>
   <col6>val6</col6>

</tab>
<tab>
<col1>v1</col1>
<col2>v2</col2>
<col3>v3</col3>
<col4>v4</col4>
<col5>v5</col5>
   <col6>v6</col6>

</tab>
</DataDS>


I basically need to create a string just with values of col1 and col2

so my final output should look like

val1   val2
1         2
a         b

 and so on

I just cannot  get to select the node with element  <tab>

Any help is greatly apprecaited.

YRKS
0
Comment
Question by:ChanderMadhaviGmail
  • 2
3 Comments
 
LVL 21

Accepted Solution

by:
Randy Poole earned 500 total points
ID: 40225759
        Dim xd As New Xml.XmlDocument()
        Dim xnn As Xml.XmlNodeList, xn1 As Xml.XmlNode
        Dim fn As String, i As Integer, xn As Xml.XmlNode

        fn = "c:\\data.xml"
        xd.PreserveWhitespace = False
        xd.Load(fn)
        xnn = xd.SelectNodes("//tab")
        For i = 0 To xnn.Count - 1
            xn = xnn.Item(i)
            xn1 = xn.SelectSingleNode("col1")
            Debug.Print(xn1.InnerText)
            xn1 = xn.SelectSingleNode("col2")
            Debug.Print(xn1.InnerText)
        Next

Open in new window

0
 

Author Comment

by:ChanderMadhaviGmail
ID: 40228089
I tried this but realized that the webservice sends this xml to my exe.
I can accept thestr as a string as is
The exact format of the string I receive from the webservice is

xperts Exchange > Web Development > Web Languages/Standards > XML > Help With Accessing Nodes Of An Xml File
Help with accessing nodes of an xml file
Asked by: ChanderMadhaviGmail
I have  an xml Which I receive from a web service in the usual format. the structure of the XML is as below

<DataDS xmlns="http://tempuri.org/DataDS.xsd>
<tab>
<col1>val1</col1>
<col2>val2</col2>
<col3>val3</col3>
<col4>val4</col4>
<col5>val5</col5>
   <col6>val6</col6>

</tab>
<tab>
<col1>v1</col1>
<col2>v2</col2>
<col3>v3</col3>
<col4>v4</col4>
<col5>v5</col5>
   <col6>v6</col6>

</tab>
</DataDS>

when I access this on my exe side
Dim strxml as string
strxml= mywebservice.mywebmethod()

dim xd as xmlDocument
xd =New XmlDocument(strXML)

when I view strxml I can see the xml shown up

when I say
xd.childNode. count =1
and
xd.childNode.Item(0).innerXML it gives me <tab>
<col1>val1</col1>
<col2>val2</col2>
<col3>val3</col3>
<col4>val4</col4>
<col5>val5</col5>
   <col6>val6</col6>

</tab>
<tab>
<col1>v1</col1>
<col2>v2</col2>
<col3>v3</col3>
<col4>v4</col4>
<col5>v5</col5>
   <col6>v6</col6>

</tab>

But I can't access the SelectsingleNode

Help Please. The only thing I would like to say is when I test my webservice and invoke the  webmethod I can see the xml with <  > in the browser. But when I do the view source i see &lt; and &gt;

When I invoke the service in the .exe I get the xml exactly as shown above.

Any help would be appreciated. Why does the load xml not
load the XML nodes correctly.

YRKS
0
 

Author Comment

by:ChanderMadhaviGmail
ID: 40228090
Please note I donot have the data.xsd in my .exe application
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

911 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now