Note that there are some explanatory texts on larger screens.

plurals
  1. POA question about DOM parser used with Python
    primarykey
    data
    text
    <p>I'm using the following python code to search for a node in an XML file and changing the value of an attribute of one of it's children.Changes are happening correctly when the node is displayed using toxml().But, when it is written to a file, the attributes rearrange themselves(as seen in the Source and the Final XML below). Could anyone explain how and why this happen? Python code:</p> <pre><code>#!/usr/bin/env python import xml from xml.dom.minidom import parse dom=parse("max.xml") #print "Please enter the store name:" for sku in dom.getElementsByTagName("node"): if sku.getAttribute("name") == "store": sku.childNodes[1].childNodes[5].setAttribute("value","Delhi,India") print sku.toxml() xml.dom.ext.PrettyPrint(dom, open("new.xml", "w")) </code></pre> <p>a part of the Source XML:</p> <pre><code>&lt;node name='store' node_id='515' module='mpx.lib.node.simple_value.SimpleValue' config_builder='' inherant='false' description='Configurable Value'&gt; &lt;match&gt; &lt;property name='1' value='point'/&gt; &lt;property name='2' value='0'/&gt; &lt;property name='val' value='Store# 09204 Staten Island, NY'/&gt; &lt;property name='3' value='str'/&gt; &lt;/match&gt; &lt;/node&gt; </code></pre> <p>Final XML :</p> <pre><code>&lt;node config_builder="" description="Configurable Value" inherant="false" module="mpx.lib.node.simple_value.SimpleValue" name="store" node_id="515"&gt; &lt;match&gt; &lt;property name="1" value="point"/&gt; &lt;property name="2" value="0"/&gt; &lt;property name="val" value="Delhi,India"/&gt; &lt;property name="3" value="str"/&gt; &lt;/match&gt; &lt;/node&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.
 

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