Note that there are some explanatory texts on larger screens.

plurals
  1. POOrganizing data with XPath in Perl
    primarykey
    data
    text
    <p>I am using this line of code to get two data entries from an XML file</p> <pre><code>perl xmlPerl.pl zbxml.xml "//zabbix_export/templates/template/items/item/name/text() | //zabbix_export/templates/template/items/item/description/text()" </code></pre> <p>Which takes the data, and displays it vertically. For example:</p> <ul> <li>name1 </li> <li>description1 </li> <li>name2 </li> <li>description2</li> </ul> <p>I used this in c# and had some code so that it would display like this</p> <ul> <li>name1 - description1</li> <li>name2 - description2</li> <li>name3 - (blank since there isnt a description)</li> </ul> <p><em>there were even some blanks in description</em>. Here is the c# code, since it may help.</p> <pre><code>XPathExpression expr; expr = nav.Compile("/zabbix_export/templates/template/items/item/name | /zabbix_export/templates/template/items/item/description"); XPathNodeIterator iterator = nav.Select(expr); //Iterate on the node set List&lt;string&gt; listBox1 = new List&lt;string&gt;(); listBox1.Clear(); try { while (iterator.MoveNext()) { XPathNavigator nav2 = iterator.Current.Clone(); // nav2.Value; listBox1.Add(nav2.Value); Console.Write(nav2.Value); iterator.MoveNext(); nav2 = iterator.Current.Clone(); Console.Write("-" + nav2.Value + "\n"); </code></pre> <p>Well, I am having to switch it to Perl now, and I am not sure if I should try and find some Perl code to do what I need, or if this can be done in XPath? I tried looking at some w3 tutorials, but didn't find what I was looking for.</p> <p>Thanks!</p> <p>edit - would I need to edit this part of my xmlPerl.pl</p> <pre><code># print each node in the list foreach my $node ( $nodeset-&gt;get_nodelist ) { print XML::XPath::XMLParser::as_string( $node ) . "\n"; } </code></pre>
    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.
    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