Logo-small

3.5.3.2 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.

Installation

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

Usage examples

Parsing a single node

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