मैं उन वस्तुओं का चयन करने के लिए XPath का उपयोग करने का प्रयास कर रहा हूं जिनके पास Location
मानों के साथ एक पहलू है, लेकिन वर्तमान में सभी आइटमों को चुनने के लिए भी मेरे प्रयास विफल हो जाते हैं: सिस्टम खुशी से रिपोर्ट करता है कि उसे 0 आइटम मिलते हैं, फिर रिटर्न (इसके बजाय नोड्स को foreach
लूप द्वारा संसाधित किया जाना चाहिए)। मैं या तो मेरी मूल क्वेरी बनाने या बस XPath को काम करने में सहायता की सराहना करता हूं।सी # XPath कुछ भी नहीं ढूंढ रहा
एक्सएमएल
<?xml version="1.0" encoding="UTF-8" ?>
<Collection Name="My Collection" SchemaVersion="1.0" xmlns="http://schemas.microsoft.com/collection/metadata/2009" xmlns:p="http://schemas.microsoft.com/livelabs/pivot/collection/2009" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<FacetCategories>
<FacetCategory Name="Current Address" Type="Location"/>
<FacetCategory Name="Previous Addresses" Type="Location" />
</FacetCategories>
<Items>
<Item Id="1" Name="John Doe">
<Facets>
<Facet Name="Current Address">
<Location Value="101 America Rd, A Dorm Rm 000, Chapel Hill, NC 27514" />
</Facet>
<Facet Name="Previous Addresses">
<Location Value="123 Anywhere Ln, Darien, CT 06820" />
<Location Value="000 Foobar Rd, Cary, NC 27519" />
</Facet>
</Facets>
</Item>
</Items>
</Collection>
सी #
public void countItems(string fileName)
{
XmlDocument document = new XmlDocument();
document.Load(fileName);
XmlNode root = document.DocumentElement;
XmlNodeList xnl = root.SelectNodes("//Item");
Console.WriteLine(String.Format("Found {0} items" , xnl.Count));
}
इस से विधि के लिए अधिक है, लेकिन जब से यह है कि मैं यह सोचते हैं रहा हूँ चलाने हो जाता है सभी है समस्या यहाँ निहित है। कॉलिंग root.ChildNodes
सटीक रूप से FacetCategories
और Items
लौटाता है, इसलिए मैं पूरी तरह से नुकसान में हूं।
आपकी मदद के लिए धन्यवाद!