संघ
आदेश दोनों नोड्स आप संघ ऑपरेटर का उपयोग करने की जरूरत है पाने के लिए - |
उदाहरण के लिए, अगले क्वेरी नोड्स के दोनों प्रकार वापस आ जाएगी - comp_div
और sty_ret_type
:
/meadinkent/record/comp_div | /meadinkent/record/sty_ret_type
फाई उप नोड्स द्वारा lter महत्व देता
आदेश फिल्टर करने के लिए नोड में अपने उप-नोड्स के आधार पर महत्व देता है आप एक ही कोष्ठक में सभी शर्तों जगह [nodeA='value1' and nodeB='value2']
उदाहरण के लिए, अगले क्वेरी रिकॉर्ड नोड्स जिसका उप नोड्स से मेल खाते हैं वापस आ जाएगी की जरूरत है फिल्टर:
/meadinkent/record[comp_div='MENSWEAR' and sty_ret_type='ACCESSORIES']
एसी # संघ उदाहरण:
[Test]
public void UnionExample()
{
string xml =
@"<meadinkent>
<record>
<comp_div>MENSWEAR</comp_div>
<sty_ret_type>ACCESSORIES</sty_ret_type>
<sty_pdt_type>BELTS</sty_pdt_type>
<pdt_category>AWESOME_BELTS</pdt_category>
</record>
</meadinkent>";
XDocument xDocument = XDocument.Parse(xml);
IEnumerable<XElement> selectedElements =
xDocument.XPathSelectElements(
"/meadinkent/record/comp_div | /meadinkent/record/sty_ret_type");
Assert.That(selectedElements.Count(), Is.EqualTo(2));
}
एसी # उप नोड्स उदाहरण के द्वारा फिल्टर:
[Test]
public void FilterExample()
{
string xml =
@"<meadinkent>
<record>
<comp_div>MENSWEAR</comp_div>
<sty_ret_type>ACCESSORIES</sty_ret_type>
<sty_pdt_type>BELTS</sty_pdt_type>
<pdt_category>AWESOME_BELTS</pdt_category>
</record>
</meadinkent>";
XDocument xDocument = XDocument.Parse(xml);
IEnumerable<XElement> selectedElements =
xDocument.XPathSelectElements(
"/meadinkent/record[comp_div='MENSWEAR' and sty_ret_type='ACCESSORIES']");
Assert.That(selectedElements.Count(), Is.EqualTo(1));
Assert.That(selectedElements.First().Name.LocalName, Is.EqualTo("record"));
}
क्षमा करें, मैं अपने आप को स्पष्ट नहीं किया है। मैं बाद में रिकॉर्ड नोड का संदर्भ है जो अंदर सभी तत्व मानों से मेल खाता है। तो अगर मैं यह कहना चाहता हूं कि sty_pdt_type "बेल्ट्स" है और pdt_category "अवेज़बेट्स" है, तो मैं उन सभी रिकॉर्ड नोड्स का संदर्भ चाहता हूं जिनके लिए वे तत्व उन मानों से मेल खाते हैं। –
@ मैट थ्रोवर, अब मैं समझता हूं कि आपका क्या मतलब है :) तदनुसार अद्यतन उत्तर। – Elisha
बहुत बढ़िया, धन्यवाद! –