Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML Document Parsing C#

Tags:

c#

xml

I have a REST web service that creates a XMLDocument I am a bit confused on how access the inner text in FormattedPrice using XMLNode. I can grad offers but that will give me all the inner text.

<Offers>
    <Offer>
       <OfferListing>
          <Price>
            <Amount>1067</Amount>
            <CurrencyCode>USD</CurrencyCode>
            <FormattedPrice>$10.67</FormattedPrice>
          </Price>
       </OfferListing>
    </Offer>
</Offers>
like image 1000
Joe Tyman Avatar asked Jan 27 '26 05:01

Joe Tyman


1 Answers

A quick walk-through of XPath will help immensely if you're using the Xml DOM.

This should meet your immediate need:

XmlNode n = doc.DocumentElement.SelectSingleNode("Offer/OfferListing/Price/FormattedPrice");

That will get you the first Offer's Formatted price (and assumes that your Offers node is the root). Other mechanisms exist in XPath that are a bit less brittle and that's where a tutorial would help you.

like image 186
dkackman Avatar answered Jan 28 '26 19:01

dkackman