Note that there are some explanatory texts on larger screens.

plurals
  1. POExtract nodes from xml based on keywords
    text
    copied!<p>I have an XML like below and am trying to extract the nodes based on a keyword. Tried using XPath and XMLLint. But obviously, I'm not doing something right. So hoping for some help in this regard.</p> <p>XML File</p> <pre><code> &lt;section&gt; &lt;h&gt;2 Introduction&lt;/h1&gt; &lt;region&gt;Intro 1&lt;/region&gt; &lt;region&gt;Background&lt;/region&gt; &lt;/section&gt; &lt;article&gt; &lt;body&gt; &lt;section&gt; &lt;h1&gt;2 Task objectives&lt;/h1&gt; &lt;region&gt;2.1 Primary objectives &lt;/region&gt; &lt;region&gt;2.&lt;/region&gt; &lt;/section&gt; &lt;section&gt; &lt;h2&gt;Requirements&lt;/h1&gt; &lt;region&gt;System Requirements &lt;/region&gt; &lt;region&gt;Technical Requirements&lt;/region&gt; &lt;/section&gt; &lt;section&gt; &lt;h3&gt;Design&lt;/h1&gt; &lt;region&gt;Design methodology &lt;/region&gt; &lt;region&gt;Design patterns&lt;/region&gt; &lt;/section&gt; &lt;/body&gt; &lt;/article&gt; </code></pre> <p>Given this XML and a keyword <code>Task objectives</code> or <code>objectives</code> (Case insensitive), I need to extract the entire node and write to another XML file</p> <pre><code>&lt;section&gt; &lt;h1&gt;2 Task objectives&lt;/h1&gt; &lt;region&gt;2.1 Primary objectives &lt;/region&gt; &lt;region&gt;2.&lt;/region&gt; &lt;/section&gt; </code></pre> <p>The extraction piece I tried using Xpath and XMllint.</p> <pre><code> $ xmllint --xpath //body//section//h1[.="Task objectives"] Prior.mod.xml XPath error : Invalid predicate //body//section//h1[.=Task objectives] ^ xmlXPathEval: evaluation failed XPath evaluation failure </code></pre> <p>Could anyone please let me know what is wrong with the above and how I can fix it? Also, I'd like to do this in a shell on a directory of files. Is XMLlint the best option?</p>
 

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