Solved

Skip root node when reading XML file using XML Read vb.net/c#

Posted on 2014-01-09
1
1,377 Views
Last Modified: 2014-01-09
Hi Guys,

I have the below code that works fine in creating a data set which populates my grid control. However I would like to skip the root node so that my data is only the child columns and its data.

 Dim web As New WebClient()
            Dim url As String = String.Format("myurltoerbsiteapi")
            Dim response As String = web.DownloadString(url)
            Dim ds As New DataSet()
            Using stringReader As New StringReader(response)
                ds = New DataSet()
                ds.ReadXml(stringReader)
            End Using
            dt = ds.Tables(0)

            Me.GridControl1.DataSource = dt

Open in new window


The returned XML from website looks like so;

<?xml version="1.0" encoding="UTF-8"?>
<results xmlns="http://companycheck.co.uk/api/search" searchTerm="databarracks" total="2"><company id="FC031496"><name>DATABARRACKS LIMITED</name><number>FC031496</number><status>Active</status><address>TOWER HILL HOUSE, 32-34 LE BORDAGE, GUERNSEY, GY1 1BP</address><country>GB</country></company><company id="04533716"><name>DATABARRACKS (UK) LTD</name><number>04533716</number><status>Active</status><address>ARXCIS HOUSE 9 PARK HILL, LONDON, SW4 9NS</address><country>GB</country></company></results>

Open in new window


I would like to read it like so in my code:

<?xml version="1.0" encoding="UTF-8"?>
<company id="FC031496"><name>DATABARRACKS LIMITED</name><number>FC031496</number><status>Active</status><address>TOWER HILL HOUSE, 32-34 LE BORDAGE, GUERNSEY, GY1 1BP</address><country>GB</country></company><company id="04533716"><name>DATABARRACKS (UK) LTD</name><number>04533716</number><status>Active</status><address>ARXCIS HOUSE 9 PARK HILL, LONDON, SW4 9NS</address><country>GB</country></company>

Open in new window


Therefore I need  way to skip the <results> root node from being read

Your help is much appreciated
0
Comment
Question by:databarracks
1 Comment
 

Accepted Solution

by:
databarracks earned 0 total points
ID: 39770307
Never mind I found my solution which was to use the node as the table name like ds.Tables("table_name").
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

706 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

19 Experts available now in Live!

Get 1:1 Help Now