Note that there are some explanatory texts on larger screens.

plurals
  1. POFinding duplicate XML nodes and minimize XML strcutre and size
    primarykey
    data
    text
    <p>I have the current XML which contains many duplicates.</p> <pre><code>&lt;XML version="1.0"&gt; &lt;body&gt; &lt;optionTree&gt; &lt;device modelDescription="20 Slot MX2000 Chassis, Base with 1 RE, SFBs, Fan Trays, AC Power" ProductId="1542671" modelCatalogNum="MX2020-BASE-AC" price="450000" quantity="1" userRemovable="1"&gt; &lt;optionItem modelDescription="MPC Slot 0" slotIndex="1" isSingleSelected="1"&gt; &lt;device modelDescription="2xTrio Chipset Enhanced MPC, 1588v2, port queuing, price includes full scale L2/L2.5 and reduced scale L3 features" ProductId="1540947" modelCatalogNum="MX-MPC2E-3D-P" price="70000"&gt; &lt;optionItem modelDescription="MIC Slot 1" slotIndex="1" isSingleSelected="1"&gt; &lt;device modelDescription="20x10/100/1000 MIC for MX, requires optics sold separately" ProductId="334748" modelCatalogNum="MIC-3D-20GE-SFP" price="9000"&gt; &lt;optionItem modelDescription="SFP Slot 1" slotIndex="1" isSingleSelected="1"&gt; &lt;device modelDescription="SFP capable of support 10/100/1000 speeds" ProductId="291564" modelCatalogNum="SFP-1GE-FE-E-T" price="395" /&gt; &lt;device modelDescription="Small Form Factor Pluggable supporting 1000BASE-EX Gigabit Ethernet Optic Module, 40km." ProductId="205359" modelCatalogNum="SFP-GE40KM" price="2500" /&gt; &lt;device modelDescription="Small Form Factor Pluggable 1000Base-SX Gigabit Ethernet Optic Module" ProductId="51804" modelCatalogNum="SFP-1GE-SX" price="500" /&gt; &lt;device modelDescription="Small Form Factor Pluggable 1000Base-T Gigabit Ethernet Module (uses Cat 5 cable)" ProductId="51805" modelCatalogNum="SFP-1GE-T" price="395" /&gt; &lt;device modelDescription="Small Form Factor Pluggable 1000Base-LH Gigabit Ethernet Optic Module" ProductId="205257" modelCatalogNum="SFP-1GE-LH" price="5995" /&gt; &lt;device modelDescription="Small Form Factor Pluggable 1000Base-LX Gigabit Ethernet Optic Module" ProductId="51803" modelCatalogNum="SFP-1GE-LX" price="995" /&gt; &lt;/optionItem&gt; &lt;optionItem modelDescription="SFP Slot 2" slotIndex="2" isSingleSelected="1"&gt; &lt;device modelDescription="SFP capable of support 10/100/1000 speeds" ProductId="291564" modelCatalogNum="SFP-1GE-FE-E-T" price="395" /&gt; &lt;device modelDescription="Small Form Factor Pluggable supporting 1000BASE-EX Gigabit Ethernet Optic Module, 40km." ProductId="205359" modelCatalogNum="SFP-GE40KM" price="2500" /&gt; &lt;device modelDescription="Small Form Factor Pluggable 1000Base-SX Gigabit Ethernet Optic Module" ProductId="51804" modelCatalogNum="SFP-1GE-SX" price="500" /&gt; &lt;device modelDescription="Small Form Factor Pluggable 1000Base-T Gigabit Ethernet Module (uses Cat 5 cable)" ProductId="51805" modelCatalogNum="SFP-1GE-T" price="395" /&gt; &lt;device modelDescription="Small Form Factor Pluggable 1000Base-LH Gigabit Ethernet Optic Module" ProductId="205257" modelCatalogNum="SFP-1GE-LH" price="5995" /&gt; &lt;device modelDescription="Small Form Factor Pluggable 1000Base-LX Gigabit Ethernet Optic Module" ProductId="51803" modelCatalogNum="SFP-1GE-LX" price="995" /&gt; &lt;/optionItem&gt; &lt;optionItem modelDescription="SFP Slot 3" slotIndex="3" isSingleSelected="1"&gt; &lt;device modelDescription="SFP capable of support 10/100/1000 speeds" ProductId="291564" modelCatalogNum="SFP-1GE-FE-E-T" price="395" /&gt; &lt;device modelDescription="Small Form Factor Pluggable supporting 1000BASE-EX Gigabit Ethernet Optic Module, 40km." ProductId="205359" modelCatalogNum="SFP-GE40KM" price="2500" /&gt; &lt;device modelDescription="Small Form Factor Pluggable 1000Base-SX Gigabit Ethernet Optic Module" ProductId="51804" modelCatalogNum="SFP-1GE-SX" price="500" /&gt; &lt;device modelDescription="Small Form Factor Pluggable 1000Base-T Gigabit Ethernet Module (uses Cat 5 cable)" ProductId="51805" modelCatalogNum="SFP-1GE-T" price="395" /&gt; &lt;device modelDescription="Small Form Factor Pluggable 1000Base-LH Gigabit Ethernet Optic Module" ProductId="205257" modelCatalogNum="SFP-1GE-LH" price="5995" /&gt; &lt;device modelDescription="Small Form Factor Pluggable 1000Base-LX Gigabit Ethernet Optic Module" ProductId="51803" modelCatalogNum="SFP-1GE-LX" price="995" /&gt; &lt;/optionItem&gt; &lt;/device&gt; &lt;/optionItem&gt; &lt;/device&gt; &lt;/optionItem&gt; &lt;/device&gt; &lt;/optionTree&gt; &lt;/body&gt; &lt;/XML&gt; </code></pre> <p>I want to minimize this XML and remove all duplicated XML nodes.</p> <p>I want to create a code does which does the following:</p> <ul> <li>Loops through this XML and finds duplicate "Device" elements.</li> <li>for each duplicate node, remove all of its attribute except for "ProductId" attribute.</li> <li>Create a legend in the bottom as follows:</li> <li>A new element called "Devices" will be created and contain full details of all the removed XML nodes.</li> </ul> <p>final XML should look like this:</p> <pre><code>&lt;XML version="1.0"&gt; &lt;body&gt; &lt;optionTree&gt; &lt;device modelDescription="20 Slot MX2000 Chassis, Base with 1 RE, SFBs, Fan Trays, AC Power" ProductId="1542671" modelCatalogNum="MX2020-BASE-AC" price="450000" quantity="1" userRemovable="1"&gt; &lt;optionItem modelDescription="MPC Slot 0" slotIndex="1" isSingleSelected="1"&gt; &lt;device modelDescription="2xTrio Chipset Enhanced MPC, 1588v2, port queuing, price includes full scale L2/L2.5 and reduced scale L3 features" ProductId="1540947" modelCatalogNum="MX-MPC2E-3D-P" price="70000"&gt; &lt;optionItem modelDescription="MIC Slot 1" slotIndex="1" isSingleSelected="1"&gt; &lt;device modelDescription="20x10/100/1000 MIC for MX, requires optics sold separately" ProductId="334748" modelCatalogNum="MIC-3D-20GE-SFP" price="9000"&gt; &lt;optionItem modelDescription="SFP Slot 1" slotIndex="1" isSingleSelected="1"&gt; &lt;device ProductId="291564" /&gt; &lt;device ProductId="205359" /&gt; &lt;device ProductId="51804" /&gt; &lt;device ProductId="51805" /&gt; &lt;device ProductId="205257" /&gt; &lt;device ProductId="51803" /&gt; &lt;/optionItem&gt; &lt;optionItem modelDescription="SFP Slot 2" slotIndex="2" isSingleSelected="1"&gt; &lt;device ProductId="291564" /&gt; &lt;device ProductId="205359" /&gt; &lt;device ProductId="51804" /&gt; &lt;device ProductId="51805" /&gt; &lt;device ProductId="205257" /&gt; &lt;device ProductId="51803" /&gt; &lt;/optionItem&gt; &lt;optionItem modelDescription="SFP Slot 3" slotIndex="3" isSingleSelected="1"&gt; &lt;device ProductId="291564" /&gt; &lt;device ProductId="205359" /&gt; &lt;device ProductId="51804" /&gt; &lt;device ProductId="51805" /&gt; &lt;device ProductId="205257" /&gt; &lt;device ProductId="51803" /&gt; &lt;/optionItem&gt; &lt;/device&gt; &lt;/optionItem&gt; &lt;/device&gt; &lt;/optionItem&gt; &lt;/device&gt; &lt;/optionTree&gt; &lt;devices&gt; &lt;device ProductId="291564" modelDescription="SFP capable of support 10/100/1000 speeds" modelCatalogNum="SFP-1GE-FE-E-T" price="395" /&gt; &lt;device ProductId="205359" modelDescription="Small Form Factor Pluggable supporting 1000BASE-EX Gigabit Ethernet Optic Module, 40km." modelCatalogNum="SFP-GE40KM" price="2500" /&gt; &lt;device ProductId="51804" modelDescription="Small Form Factor Pluggable 1000Base-SX Gigabit Ethernet Optic Module" modelCatalogNum="SFP-1GE-SX" price="500" /&gt; &lt;device ProductId="51805" modelDescription="Small Form Factor Pluggable 1000Base-T Gigabit Ethernet Module (uses Cat 5 cable)" modelCatalogNum="SFP-1GE-T" price="395" /&gt; &lt;device ProductId="205257" modelDescription="Small Form Factor Pluggable 1000Base-LH Gigabit Ethernet Optic Module" modelCatalogNum="SFP-1GE-LH" price="5995" /&gt; &lt;device ProductId="51803" modelDescription="Small Form Factor Pluggable 1000Base-LX Gigabit Ethernet Optic Module" modelCatalogNum="SFP-1GE-LX" price="995" /&gt; &lt;/devices&gt; &lt;/body&gt; &lt;/XML&gt; </code></pre> <p>I have already found a code that finds duplicate XML nodes, However I want to do more than just find those duplicates as I described above.</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.
    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