Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

How to read an Xml RSS

1 reply

Last post Mar 14, 2008 01:00 PM by mchlsync

(0)
  • nafisa

    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

    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.

     


     

    (If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

    Regards,
    Michael Sync
    Silverlight MVP

    Blog : http://michaelsync.net