XML Tutorials - Herong's Tutorial Examples - v5.25, by Herong Yang
XPath Query with XML Tools on Atom
This section provides a tutorial example on how to use XML Tools package in Atom to run XPath query on any XML documents.
As described in the previous tutorial, "XML Tools" package on Atom offers 3 commands: Pretty-print format, Compress white spaces, and XPath query.
The first 2 commands are not that important. But the last command is important if you are developing XPath expressions to be used in your XSLT templates or other applications. You can open any input XML document and run queries to validate your XPath expressions interactively.
1. Open XML document, dictionary.xml, in Atom:
<?xml version="1.1"?> <!-- dictionary.xml - Copyright (c) 2002-2018 HerongYang.com. All Rights Reserved. --> <dictionary> <word acronym="true"> <name>XML</name> <definition reference="Herong's Notes">eXtensible Markup Language.</definition> <update date="2022-12-23"/> </word> <word symbol="true"> <name><</name> <definition>Mathematical symbol representing the "less than" logical operation, like: 1<2.</definition> <definition>Reserved symbol in XML to representing the beginning of tags, like: <![CDATA[<p>Hello world!</p>]]> </definition> </word> </dictionary>
2. Click "Packages > XML Tools > Query Document". The XPath query box shows up.
3. Enter XPath expression "//@date". 1 matched attribute found as I expected. Remember that default context assumes that the root element is the current node.
4. Enter XPath expression "//word[@symbol='true']". 1 matched element found as I expected.
5. Enter XPath expression "//definition". 3 matched elements found as I expected.
6. Enter XPath expression "//definition[1]". 2 matched elements found as I expected.
7. Enter XPath expression "//*[name()='word']". 2 matched elements found as I expected.
Cool. Now I have a nice tool to validate any XPath expression against any XML document.
Table of Contents
Introduction of XML (eXtensible Markup Language)
DOM (Document Object Model) Programming Interface
SAX (Simple API for XML) Programming Interface
DTD (Document Type Definition) Introduction
Validating an XML Document against the Specified DTD Document Type
XSD (XML Schema Definition) Introduction
Validating XML Documents Against Specified XML Schemas
XSL (Extensible Stylesheet Language) Introduction
XSLT (XSL Transformations) Introduction
XSLT Elements as Programming Statements
Control and Generate XML Element in the Result
PHP Extensions for XML Manipulation
Processing XML with Python Scripts
XML Tools Plugin for Notepad++
►XML Plugin Packages for Atom Editor
►XPath Query with XML Tools on Atom
atom-xsltransform Package for Atom