7/40 - XPath, Let's Get Selecting
- christophernmiller
- Feb 7
- 1 min read
Updated: Apr 28
Interestingly enough, XPath was derived from a W3Schools suggestion. There are a few XPath Expressions that make selecting data from XML objects especially useful.
XPath is SQL
In the sense that both Structured Query Language(SQL) and XPath perform queries, they are the same. XPath uses a variety of expressions to communicate with the data it stores as objects. For example, we will add two more cars to the list we created in this blog.
Updated Car Dealership
Now that we have added the additional cars to our XML Object, we can select or query using the XPath Expressions.
const xpath = "//car[model='Explorer']";
const result = xmlDoc.evaluate(xpath, xmlDoc, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;We will learn more about the different functions in a later post. There are over 200 XPath functions.




Comments