?
Solved

Help with accessing nodes of an xml file

Posted on 2014-07-28
3
Medium Priority
?
125 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
[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
  • 2
3 Comments
 
LVL 21

Accepted Solution

by:
Randy Poole earned 2000 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

Automating Terraform w Jenkins & AWS CodeCommit

How to configure Jenkins and CodeCommit to allow users to easily create and destroy infrastructure using Terraform code.

Question has a verified solution.

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

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…
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
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 …
Progress

764 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