Sign In|Join
Home/Silverlight.NET Forums/General Silverlight Programming/Programming with .NET - General/How to read an Xml
Last post Mar 14, 2008 01:00 PM by mchlsync
Member
18 Points
29 Posts
Mar 14, 2008 12:28 PM | LINK
Hello
I have the following Xml file
<?xml version="1.0" encoding="UTF-8" ?>
<ItemSearchResponse >
<Items>
<Item>
<LowestNewPrice>
<Amount>1845</Amount>
<CurrencyCode>USD</CurrencyCode>
<FormattedPrice>$18.45</FormattedPrice>
</LowestNewPrice>
<LowestUsedPrice>
<Amount>1836</Amount>
<FormattedPrice>$18.36</FormattedPrice>
</LowestUsedPrice>
</OfferSummary>
</Items>
</ItemSearchResponse>
Thanx.
Star
14968 Points
2799 Posts
Mar 14, 2008 01:00 PM | LINK
Step #1: Set your XML as embedded resource.
Step #2: Use the following code to read XML
Stream stream = this.GetType().Assembly.GetManifestResourceStream("SilverlightProject1.Configs.xml"); XmlReader reader = XmlReader.Create(stream); while (reader.Read()) { if (reader.IsStartElement()) { if ("ServiceUriString" == reader.LocalName) { reader.Read(); string _serviceURL = reader.Value; reader = null; stream.Dispose(); return _serviceURL; } } } reader = null; stream.Dispose(); return string.Empty;
Note: You have to customize the code as you need based on your XML.
nafisa
Member
18 Points
29 Posts
How to read an Xml
Mar 14, 2008 12:28 PM | LINK
Hello
I have the following Xml file
<?xml version="1.0" encoding="UTF-8" ?>
<ItemSearchResponse >
<Items>
<Item>
<OfferSummary><LowestNewPrice>
<Amount>1845</Amount>
<CurrencyCode>USD</CurrencyCode>
<FormattedPrice>$18.45</FormattedPrice>
</LowestNewPrice>
<LowestUsedPrice>
<Amount>1836</Amount>
<CurrencyCode>USD</CurrencyCode>
<FormattedPrice>$18.36</FormattedPrice>
</LowestUsedPrice>
</OfferSummary>
</Item></Items>
</ItemSearchResponse>
I wanna read this xml through XDocument and want to show the Formatted prices in DataGrid. Currently m using Silverlight 2.0, plz !!! anybody can tell me d exact procedure for reading d above Xml or can send me code for the same.Thanx.
mchlSync
Star
14968 Points
2799 Posts
Re: How to read an Xml
Mar 14, 2008 01:00 PM | LINK
Step #1: Set your XML as embedded resource.
Step #2: Use the following code to read XML
Stream stream = this.GetType().Assembly.GetManifestResourceStream("SilverlightProject1.Configs.xml");
XmlReader reader = XmlReader.Create(stream);
while (reader.Read()) {
if (reader.IsStartElement()) {
if ("ServiceUriString" == reader.LocalName) {
reader.Read();
string _serviceURL = reader.Value;
reader = null;
stream.Dispose();
return _serviceURL;
}
}
}
reader = null;
stream.Dispose();
return string.Empty;
Note: You have to customize the code as you need based on your XML.
Regards,
Michael Sync
Silverlight MVP
Blog : http://michaelsync.net