Possible Duplicate:
Find values under one node in XML
Sample XML File:
<Book>
<Page id="1">
<Head>Preface</Head>
<Body>
<Paragraph>
<Line>
<Word>
<Char>T</Char>
<Char>h</Char>
<Char>i</Char>
<Char>s</Char>
</Word>
<Word>is sample xml file.</Word>
</Line>
</Paragraph>
</Body>
</Page>
Note: Here, sample text to search is ‘I’.
For Selection Word without having nodes , xPath expression is:
string Word_Char_XPath="//CHAR[contains(translate(text(),'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ'),'I')]/..";
For selection of words having only nodes, xPath expression is:
string Word_XPath="//WORD[contains(translate(text(), abcdefghijklmnopqrstuvwxyz, ABCDEFGHIJKLMNOPQRSTUVWXYZ), 'I')]";
Code for selection of words containing “i”
XmlDocument objXmlDoc = new XmlDocument();
XmlNodeList objXmlNodeList;
objXmlDoc.Load(sFilePath);
objXmlNodeList = objXmlDoc.SelectNodes(Word_Char_XPath+" or "+ Word_XPath);
Problem:
By ‘or’ two xpath expression it returns either true or false, but if all word nodes to be selected on matching criteria (both xpaths)then how it can be achieved ?
Well, I’ve solved it by getting some help form Net.
Where I’s using ‘or‘ operator, use ‘|‘ (Pipe Sign) operator to combine the values of two XPath Expression. It will select all the nodes in xml file which match either condition in XPath expression.
Happy Programming !