Open atc0005 opened 4 years ago
Notes below were taken while watching the 9. XPath examples and demonstrations in XML video.
The plants.xml
file was the sample XML document used by Brandon Jones (GitHub, YouTube) in the XPath examples shown in the video.
Other tools used in the video:
Examples pulled 1:1
from Notepad++ screenshot:
/plant/specimens
/plant/specimens/specimen[1]
/plant/specimens/specimen[last()]
/plant/specimens/specimen[longitude>3]
/plant/specimens/specimen[longitude>3]/comments
/plant/specimens/specimen[longitude>3]/../../genus
My scratch notes:
../../
//species
species
, no matter where it lives in the document//latitude
//species
, will return all occurrences no matter where it lives in the document//specimen[latitude>0]/latitude
or //..[latitude>0]/latitude
//..[latitude>0]/latitude
I picked up this bit (watched this video before Brandon Jones' video series where he also covered this) from the XPath Basics Tutorial HD video.
This (incomplete) syntax:
food[@name='tacos']
indicates that you want to filter the food
elements by the name=tacos
attribute:
<food name="tacos">
The video is relatively short, but gave a great overview. The free XML Quire
application is used in the examples.
Background
I'm using (or trying to use) XPath with the atc0005/go-lockss project. That project processes a LOCKSS XML configuration file served up by a central network configuration server and then attempts to verify connectivity from the current node (where the app is running) to all peer nodes.
As part of this work, I've stumbled my way through using the https://github.com/antchfx/xmlquery package to process the XML file and retrieve the values I'm looking for. I thought I understood what was happening, but as atc0005/go-lockss#21 notes, I'm not getting the expected results.
In short, there is a bug with the application and I'm not (yet) knowledgeable enough to fix it properly. Thankfully the app's assumptions work as intended for two of the LOCKSS networks that I've tested against, but more work is needed to properly parse the XML file to work with other networks where group-based peers are configured.
Parsing that file will require a better understanding of XPath than I currently have.
What I've found
Guides
Videos
plants.xml
file used in videoTools