Logo-small XPath

It is a basic XPath library. Modifies XMLNode included in the XMLParser package to better support XPath. Handles basic XPath locator expressions for elements and attributes; returns a collection of XMLNodes matching the expression, if any.


Open the Configuration Browser, select XPath, and click Install.

Usage examples

Parsing a single node

| xml doc |
xml := '<root>
doc := XMLDOMParser on: xml.
(XPath for: 'root/topChild') in: doc parseDocument
| xml doc |
xml := '<?xml version="1.0" encoding="UTF-8" ?>
<item type="attvalue">nodevalue</item>
</first> '
doc := XMLDOMParser on: xml.
(XPath for: 'first') in: doc parseDocument

Parsing from a XML document

For this example download a XML file for testing purposes: http://unicode.org/repos/cldr/trunk/common/supplemental/supplementalData.xml

| doc results |
doc := XMLDOMParser parseDocumentFromFileNamed: 'supplementalData.xml'.
results := ( XPath for: '/languageData/language/@type' ) in: doc.
results explore

Add a Note

Licensed under Creative Commons BY-NC-SA | Published using Pier |