Case-Insensitive XPath Searching

As far as I know, there is no such xpath function to do the case-insenstive search.
However, there is a work-around for this.
The solution is to receive a lower-case string as the input and use lower-case() xpath function to help perform the search.
Consider the following XML:

<?xml version="1.0" encoding="UTF-8"?>
<specification>
  <name>ASUS Striker</name>
  <manufacturer>ASUS</manufacturer>
  <model>Striker</model>
</specification>

The following xpath do the search for “asu” which returns two string – “asus striker” and “asus”:

/specification//lower-case(text())[contains(.,'asu')]

As we can see, using lower-caes() and contains() helps search for lower-case string even though the xml contains upper-case string.
The text() function indicates the value of the node in context.
You can also try name() which indicates the name of the node.
You can try using upper-case() with upper-case input string as well.

The Mystery of XmlNode.SelectNodes()

With the xml document found here and the following code, what will you get as the result?
Shortened version of the XML document:
    <Items>
        <ItemAttributes>
            <ListPrice>
                <FormattedPrice>$49.00</FormattedPrice>
            </ListPrice>
        </ItemAttributes>
        <OfferSummary>
            <LowestNewPrice>
                <FormattedPrice>$29.99</FormattedPrice>
            </LowestNewPrice>
            <LowestUsedPrice>
                <FormattedPrice>$24.99</FormattedPrice>
            </LowestUsedPrice>
        </OfferSummary>
        <Offers>
            <Offer>
                <FormattedPrice>$..(1)..</FormattedPrice>
            </Offer>
            <Offer>
                <FormattedPrice>$..(2)..</FormattedPrice>
            </Offer>
            <Offer>
                <FormattedPrice>$..(3)..</FormattedPrice>
            </Offer>
            <Offer>
                <FormattedPrice>$..(4)..</FormattedPrice>
            </Offer>
            <Offer>
                <FormattedPrice>$..(5)..</FormattedPrice>
            </Offer>
            <Offer>
                <FormattedPrice>$..(6)..</FormattedPrice>
            </Offer>
            <Offer>
                <FormattedPrice>$..(7)..</FormattedPrice>
            </Offer>
            <Offer>
                <FormattedPrice>$..(8)..</FormattedPrice>
            </Offer>
            <Offer>
                <FormattedPrice>$..(9)..</FormattedPrice>
            </Offer>
            <Offer>
                <FormattedPrice>$..(10)..</FormattedPrice>
            </Offer>
        </Offers>
    </Items>
</ItemLookupResponse>
XmlDocument xDoc = new XmlDocument();
xDoc.Load(“resources/ItemLookupResponse.xml”);
XmlNamespaceManager nsMgr = new XmlNamespaceManager(xDoc.NameTable);
nsMgr.AddNamespace(“aws”, xDoc.DocumentElement.NamespaceURI);
XmlNode offersNode = xDoc.SelectSingleNode(“//aws:Offers[1]“, nsMgr);
XmlNodeList formattedPriceNodes = offersNode.SelectNodes(“//aws:FormattedPrice”, nsMgr);
return formattedPriceNodes.Count;
Since formattedPriceNodes selects nodes under offersNode, I expected it to return 10.
But it returns 13!!!
That means it parses the whole document (xDoc), not just the node (offersNode).
The problem seems to be on the XPath expression.
Using // will parse the whole document.
To get all the matched descendant nodes, use “.//” or ”descendant::“.
Change the line with //aws:FormattedPrice to be as followed:
XmlNodeList formattedPriceNodes = offersNode.SelectNodes(“descendant::aws:FormattedPrice”, nsMgr);

The result is now 10 as expected. :D