Avatar of databarracks
databarracks
 asked on

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

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
.NET ProgrammingVisual Basic.NETWCF

Avatar of undefined
Last Comment
databarracks

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
databarracks

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck