Solved

Help with accessing nodes of an xml file

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This article will show, step by step, how to integrate R code into a R Sweave document
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 seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

746 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

13 Experts available now in Live!

Get 1:1 Help Now