Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is example of <code>XML::Twig</code> usage. The main advantage is that it is not holding whole file in memory, so processing is much faster. The code below is trying to emulate operation of script from question.</p> <pre><code>use XML::Twig; my %strings = (); XML::Twig-&gt;new( twig_handlers =&gt; { 'strings/string' =&gt; sub { $strings{ lc $_-&gt;first_child('name')-&gt;text } = $_-&gt;first_child('id')-&gt;text }, } )-&gt;parsefile('B.xml'); print "&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\n&lt;npc_templates xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"npcs.xsd\"&gt;\n"; XML::Twig-&gt;new( twig_handlers =&gt; { 'npc_client' =&gt; sub { my $nameid = eval { $strings{ lc $_-&gt;first_child('desc')-&gt;text } }; # calculate rank as needed my $hpgauge_level = eval { $_-&gt;first_child('hpgauge_level')-&gt;text }; $rank = $hpgauge_level &gt;= 28 ? 'ERROR' : $hpgauge_level &gt; 25 ? 'LEGENDARY' : $hpgauge_level &gt; 21 ? 'HERO' : $hpgauge_level &gt; 10 ? 'ELITE' : $hpgauge_level &gt; 0 ? 'NORMAL' : $hpgauge_level; my $npc_id = eval { $_-&gt;first_child('id')-&gt;text }; my $name = eval { $_-&gt;first_child('name')-&gt;text }; my $tribe = eval { $_-&gt;first_child('tribe')-&gt;text }; my $scale = eval { $_-&gt;first_child('scale')-&gt;text }; my $race_type = eval { $_-&gt;first_child('race_type')-&gt;text }; print qq|\t&lt;npc_template npc_id="$npc_id" name="$name" name_id="$nameid" height="$scale" rank="$rank" tribe="$tribe" race="$race_type" hp_gauge="$hpgauge_level"/&gt;\n|; $_-&gt;purge; } } )-&gt;parsefile('A.xml'); print "&lt;/&lt;npc_templates&gt;"; </code></pre>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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