Note that there are some explanatory texts on larger screens.

plurals
  1. POXPath-REXML-Ruby: Selecting multiple siblings/ancestors/descendants
    primarykey
    data
    text
    <p>This is my first post here. I have just started working with Ruby and am using REXML for some XML handling. I present a small sample of my xml file here: </p> <pre><code> &lt;record&gt; &lt;header&gt; &lt;identifier&gt;oai:lcoa1.loc.gov:loc.gmd/g3195.ct000379&lt;/identifier&gt; &lt;datestamp&gt;2004-08-13T15:32:50Z&lt;/datestamp&gt; &lt;setSpec&gt;gmd&lt;/setSpec&gt; &lt;/header&gt; &lt;metadata&gt; &lt;titleInfo&gt; &lt;title&gt;Meet-konstige vertoning van de grote en merk-waardige zons-verduistering&lt;/title&gt; &lt;/titleInfo&gt; &lt;/metadata&gt; &lt;/record&gt; </code></pre> <p>My objective is to match the last numerical value in the tag with a list of values that I have from an array. I have achieved this with the following code snippet:</p> <pre><code>ids = XPath.match(xmldoc, "//identifier[text()='oai:lcoa1.loc.gov:loc.gmd/"+mapid+"']") </code></pre> <p>Having got a particular identifier that I wish to investigate, now I want to go back to and select and then select to get the value in the node for that particular identifier.</p> <p>I have looked at the XPath tutorials and expressions and many of the related questions on this website as well and learnt about axes and the different concepts such as ancestor/following sibling etc. However, I am really confused and cannot figure this out easily.</p> <p>I was wondering if I could get any help or if someone could point me towards an online resource "easy" to read.</p> <p>Thank you.</p> <p>UPDATE: </p> <p>I have been trying various combinations of code such as:</p> <pre><code>idss = XPath.match(xmldoc, "//identifier[text()='oai:lcoa1.loc.gov:loc.gmd/"+mapid+"']/parent::header/following-sibling::metadata/child::mods/child::titleInfo/child::title") </code></pre> <p>The code compiles but does not output anything. I am wondering what I am doing so wrong.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload