Shakespeare asked "What's in a name? A rose by any another name would smell just as sweet." But he never worked in XML.
I was inside XML Notepad, looking at an XML file trying to debug an XSLT issue. I was pretty happy to see that XML Notepad had a Find dialog box that supported XPath. I threw in the XPath for the element I was looking for, and it produced a "Not Found" error.
In the picture above, you can see that I'm using this XPath:
I was confused, especially because the Java program that I was debugging processes this XPath correctly. So why wasn't the XPath working inside of XML Notepad? Staring at the error, I noticed that the message lists the prefixes for the each of the namespaces. In a spark of insight (aided by these references: [1] and [2]), I realized that I needed to add the prefixes to each of my elements!
In the picture above, XML Notepad now happily found my element. The XPath is now:
Adding the namespace helped! If Shakespeare were an XML coder, he'd be saying "A rose by any another name would smell just as sweet, provided you're in the right namespace."
/statistics/index_preparation/stat[attribute::name="Sorts"]
/a:statistics/a:index_preparation/a:stat[attribute::name="Sorts"]</p>
Tags: