Note that there are some explanatory texts on larger screens.

plurals
  1. POModifying tags of an XML
    primarykey
    data
    text
    <p>I'm looking for the best way to dynamically modify the tags of a very large XML file.</p> <p>Consider the following input XML:</p> <p><strong>Input</strong></p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;rootTag&gt; &lt;dictionary&gt; &lt;name&gt;field1&lt;/name&gt; &lt;address&gt;field2&lt;/address&gt; &lt;gender&gt;field3&lt;/gender&gt; . . &lt;postcode&gt;field30&lt;/postcode&gt; &lt;/dictionary&gt; &lt;records&gt; &lt;record&gt; &lt;field id="field1"&gt;John&lt;/field&gt; &lt;field id="field2"&gt;Svalbard&lt;/field&gt; &lt;field id="field3"&gt;M&lt;/field&gt; . . &lt;field id="field30"&gt;12345&lt;/field&gt; &lt;/record&gt; . . &lt;record&gt; . . &lt;/record&gt; &lt;/records&gt; &lt;/rootTag&gt; </code></pre> <p>The XML file contains a dictionary on top and a huge chunk of record nodes, whose tags are linked to the dictionary.</p> <p>I'd like to replace the <strong>tags</strong> within each record node to their corresponding value from the dictionary. Thus, the output should look like:</p> <p><strong>Output</strong></p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;rootTag&gt; &lt;records&gt; &lt;record&gt; &lt;name&gt;John&lt;/name&gt; &lt;address&gt;Svalbard&lt;/address&gt; &lt;gender&gt;M&lt;/gender&gt; . . &lt;postcode&gt;12345&lt;/postcode&gt; &lt;/record&gt; . . &lt;record&gt; . . &lt;/record&gt; &lt;/records&gt; &lt;/rootTag&gt; </code></pre> <p>Keeping in mind that there are a tremendously large number of <code>&lt;record&gt;</code> nodes, what's the best way to achieve this transformation in Java?</p> <p>Note that I only want to change the tags and not the attributes.</p>
    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.
 

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