Solved

Help with accessing nodes of an xml file

Posted on 2014-07-28
3
116 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Exit the loop 4 42
draw a Christmas tree by using a nested loop? 26 62
Embarcadero C++ builder XE10.1 Berlin TRegistry declaration 1 28
printf performancy 11 38
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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.
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 …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

770 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