Click here to Skip to main content
15,889,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi friends,
i need to parse xml document and store values in different variables or array.
here my xml document
XML
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <GetReviewsFromManufacturerCategoryAndTypeResponse xmlns="http://www.caranddriving.com/ws">
      <GetReviewsFromManufacturerCategoryAndTypeResult>
        <code>0</code>
        <message />
        <count>8</count>
        <reviewlist>
          <review>
            <reviewid>309171</reviewid>
            <manufacturer>Audi</manufacturer>
            <nameofcar>Audi A1</nameofcar>
        <paragraphlist>
              <paragraph>
                <type>By Line</type>
                <headline />
                <text>Audi's A1 might well be at its best when fitted with a particularly clever 1.4-litre petrol engine. Andy Enright reports.</text>
              </paragraph>
              <paragraph>
                <type>Ten Second Review</type>
                <headline>Ten Second Review</headline>
                <text>The A1 1.4 TFSI CoD features a modern turbocharged petrol engine that features a cylinder cut-off system which means that when cruising, it'll run on two rather than four cylinders. The result? Economy of 60.1mpg, yet it has the ability to nip to 60mph in less than 8 seconds.</text>
              </paragraph>
 </paragraphlist>
<photolist>
              <photo>
                <mini>http://f2.caranddriving.com/images/new/mini/AudiA114TFSICoD0313(2).jpg</mini>
                <std>http://f2.caranddriving.com/images/new/std/AudiA114TFSICoD0313(2).jpg</std>
                <big>http://f2.caranddriving.com/images/new/big/audia114tfsicod0313(2).jpg</big>
                <large>http://f2.caranddriving.com/images/new/large/AudiA114TFSICoD0313(2).jpg</large>
                <isdefault>false</isdefault>
              </photo>
              <photo>
                <mini>http://f2.caranddriving.com/images/new/mini/AudiA114TFSICoD0313.jpg</mini>
                <std>http://f2.caranddriving.com/images/new/std/AudiA114TFSICoD0313.jpg</std>
                <big>http://f2.caranddriving.com/images/new/big/audia114tfsicod0313.jpg</big>
                <large>http://f2.caranddriving.com/images/new/large/AudiA114TFSICoD0313.jpg</large>
                <isdefault>true</isdefault>
              </photo>
</photolist>
</review>
<review>
            <reviewid>8985</reviewid>
            <manufacturer>Audi</manufacturer>
            <nameofcar>Audi A1 1.6 TDI SE</nameofcar>
<paragraphlist>
              <paragraph>
                <type>By Line</type>
                <headline />
                <text>Audi's A1 might well be at its best when fitted with a particularly clever 1.4-litre petrol engine. Andy Enright reports.</text>
              </paragraph>
              <paragraph>
                <type>Ten Second Review</type>
                <headline>Ten Second Review</headline>
                <text>The A1 1.4 TFSI CoD features a modern turbocharged petrol engine that features a cylinder cut-off system which means that when cruising, it'll run on two rather than four cylinders. The result? Economy of 60.1mpg, yet it has the ability to nip to 60mph in less than 8 seconds.</text>
              </paragraph>
 </paragraphlist>
<photolist>
              <photo>
                <mini>http://f2.caranddriving.com/images/new/mini/AudiA114TFSICoD0313(2).jpg</mini>
                <std>http://f2.caranddriving.com/images/new/std/AudiA114TFSICoD0313(2).jpg</std>
                <big>http://f2.caranddriving.com/images/new/big/audia114tfsicod0313(2).jpg</big>
                <large>http://f2.caranddriving.com/images/new/large/AudiA114TFSICoD0313(2).jpg</large>
                <isdefault>false</isdefault>
              </photo>
              <photo>
                <mini>http://f2.caranddriving.com/images/new/mini/AudiA114TFSICoD0313.jpg</mini>
                <std>http://f2.caranddriving.com/images/new/std/AudiA114TFSICoD0313.jpg</std>
                <big>http://f2.caranddriving.com/images/new/big/audia114tfsicod0313.jpg</big>
                <large>http://f2.caranddriving.com/images/new/large/AudiA114TFSICoD0313.jpg</large>
                <isdefault>true</isdefault>
              </photo>
</photolist>
</review>
  </GetReviewsFromManufacturerCategoryAndTypeResult>
    </GetReviewsFromManufacturerCategoryAndTypeResponse>
  </soap:Body>
</soap:Envelope>



from this xml document,it have two review list.
but i need to find that which review has car name as "Audi A1" and extract datas(manufacturer,photo,paragraph) of that particular node.

any one help me write the xml parser.

Regards,
Lalitha
Posted

"any one help me write the xml parser."

Why? Microsoft already wrote it...XmlDocument Class[^]
 
Share this answer
 
Hi,

Try this.

C#
XDocument xDocument = XDocument.Parse(xml);

            string manufacturer = string.Empty;
            var aa = xDocument.Descendants("review").Where(x => x.Element("nameofcar").Value.Equals("Audi A1"));

            foreach (var a in aa)
            {
                manufacturer = a.Element("manufacturer").Value;
            }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900