Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi guys,

i have one little problem, but i can´t solve this ..
I have one xml file, and if user ask to program for search some value in xml, it can find it and get path to this place, where we can find searching value.

Example ...
i have this one xml file and i want find value 650 in calories node, and finally i want get path where i can find this value ... breakfast_menu/food/calories

XML
<breakfast_menu>
  <food>
    <name>SKUSAM NIECO NOVE</name>
    <price>$5.95</price>
    <description>
two of our famous Belgian Waffles with plenty of real maple syrup
</description>
    <calories>650</calories>
  </food>
  <food>
    <name>Strawberry Belgian Waffles</name>
    <price>$7.95</price>
    <description>
light Belgian waffles covered with strawberries and whipped cream
</description>
    <calories>900</calories>
  </food>
  <food>
    <name>Berry-Berry Belgian Waffles</name>
    <price>$8.95</price>
    <description>
light Belgian waffles covered with an assortment of fresh berries and whipped cream
</description>
    <calories>900</calories>
  </food>
  <food>
    <name>French Toast</name>
    <price>$4.50</price>
    <description>
thick slices made from our homemade sourdough bread
</description>
    <calories>600</calories>
  </food>
</breakfast_menu>



Could somebody help me how can i solve this please? or in better way, could somebody hold source?
Posted
Comments
Sergey Alexandrovich Kryukov 16-May-13 14:17pm    
Why this way? What are you going to do if you find the path? Why not reading all the data into some data structure? Why not read it all in XML DOM? What is "hold source" and why?
—SA

Please see my comments to the answers. .NET FCL suggests some different ways of working with XML. Please see my short overview of those approaches:

  1. Use System.Xml.XmlDocument class. It implements DOM interface; this way is the easiest and good enough if the size if the document is not too big.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^].
  2. Use the classes System.Xml.XmlTextWriter and System.Xml.XmlTextReader; this is the fastest way of reading, especially is you need to skip some data.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmlwriter.aspx[^], http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx[^].
  3. Use the class System.Xml.Linq.XDocument; this is the most adequate way similar to that of XmlDocument, supporting LINQ to XML Programming (please see the link at the end).
    See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^], http://msdn.microsoft.com/en-us/library/bb387063.aspx[^].


See also: http://msdn.microsoft.com/en-us/library/bb387098.aspx[^].

Good luck,
—SA
 
Share this answer
 
v2
Have a look here on how to read an XML file with C#:

Click here[^]
 
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