Groups > Asp .Net > ASP.NET XML Web Services > Re: Loading XML from website




Loading XML from website

Loading XML from website
Wed, 2 Apr 2008 10:02:54 +0000
Hi 'm new here what i do is send afew parameters to a webserver and get back an
xml file but i have worked with xml in application but not asp.net using c# what
i need to do is take what i want from it and display the information the xml is
like this <?xml version="1.0" encoding="windows-1252"
?>-<properties pagecount="1" page="1"
total="4" gid="819" gtyp="0" styp="0"
perpage="5" portfolio="0">-<pages
number="1"> <pagenumber="1" selected="true"
hidden="0" /> </pages>-<property id="1154193"
eid="819" ebid="1381" rescomnew="1"
updated="11 Mar 2008 12:17:05" featured="False"
picture="0" sold="0" price="€100,000"
priceconv="£78,842" priceval="100000"
priceconval="78842" hits="2" bedrooms="0"
bathrooms="0" receptions="0" garages="0"
gardens="0" otherrooms="0" specials="0"
ehouse="0" metopix="0" leasetype="6"
ptype="5"> <num/> <sa1>Las Terrazas El Coto de
Gol</sa1> <sa2/> <twn>La Manga Club</twn> <cty/>
<cnty/> <pc>30385</pc> <ctry/>
<loc>(1)(7)</loc> <pricetext/>
<description>sssssssssssssssssssss</description> <ea_tel>0034
968 175 532</ea_tel> </property>  the <property> is repeated
so what i would like to do is maybe turn it into a datatable for each
<property> add a row to that datatable and then i can use it how i would
like how would i go about doing this Please help
Post Reply
Re: Loading XML from website
Thu, 3 Apr 2008 10:23:02 +0000
use System.Xml.XmlTextReader.

XmlTextReader reader = new XmlTextReader(<filename>);


or XmlTextReader reader = new XmlTextReader(new
System.IO.StringReader(<xmlString>));

if it is an xml string and not a file. 

 

then parsethrough the doc like it were a stream using,

while(reader.Read()) ;

In the while loop check for your nodes/elements/attributes/data etc. as
required. 

 

for eg.

while(reader.Read()) {
    if(reader.IsStartElement() && 
            reader.Name.Equals("twn")) {

        String townName = reader.ReadString();
    } 
} 

will read the value in the <twn> tag. 

Hope that helps.
Post Reply
Re: Loading XML from website
Thu, 3 Apr 2008 10:27:09 +0000
thanks will give that a try
Post Reply
Re: Loading XML from website
Thu, 3 Apr 2008 11:13:54 +0000
ok have tried that and it does what i need but i can't select the
<property> tag doesn't display and i need the information in there how
would incorpate it?
Post Reply
Re: Loading XML from website
Thu, 3 Apr 2008 12:10:45 +0000
The things "inside" the property tags are called attributes and they
can be read by:

if(reader.IsStartElement() && 
                reader.Name.Equals("property")) {
        String propertyID = reader.GetAttribute("id");
}
Post Reply
about | contact