Seemingly inconsistent Chrome XPath results
I have a very simple XML document that I've retrieved from a larger parent. See 'accountxml' below:
<accounts xmlns="https://domain.com/path">
<customerid>sometext</customerid>
<login>sometext</login>
<companyname>sometext</companyname>
<canmanageclients>sometext</canmanageclients>
</accounts>
Simple enough - just one namespace URL (the URL referred to as ns2 in myNS namespace map below). Querying login:
accountxml.evaluate('//ns2:login',accountxml,myNS,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue;
returns OK:
<login>sometext</login>
But:
accountxml.evaluate('//ns2:customerid',accountxml,myNS,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue;
Returns:
null
This is such a simple query I'm surprised it breaks. But I can reproduce it 100% of the time. Am I doing som开发者_如何学Goething wrong, or is this a bug in Chrome?
Thanks to Gael for encouraging me to look at capitalization again.
The key to this is the document is taken from a larger parent. Although the small document above is printed exactly as the JS console sees it - with all element names in lower case, the larger parent it is taken from uses initialLowerCase for the element names.
Even though I'm querying the smaller fragment, I still need to use the casing of the parent rather than the casing of the child.
accountxml.evaluate('//ns2:customerId',accountxml,myNS,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue;
I'm not sure if this is a Chrome bug or an expected behavior.
精彩评论