Solved

Help with accessing nodes of an xml file

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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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 …

733 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