python - Append child in the middle -


I want to add an element to an XML file using a minidom from Python. Suppose I have the following XML file

  & lt; Node-a & gt; & Lt; Node 1 / & gt; & Lt; Node2 / & gt; & Lt; Node -3 / & gt; & Lt; Node one / & gt;   

In this case I can easily add an element like "node4"

  node4 = designDOM.createElement ('node4') nodea .appendChild (node4)   

resulting with the following XML:

  & lt; Node One & gt; & Lt; Node 1 / & gt; & Lt; Node2 / & gt; & Lt; Node -3 / & gt; & Lt; Node-4 / & gt; & Lt; Node one / & gt;   

My search is: If I want to force entry of an element to a place at the end in a specific position ... what should I do? For example if I want to have an element like "2-A" in the following XML, which combine me?

  & lt; Node-a & gt; & Lt; Node 1 / & gt; & Lt; Node2 / & gt; & Lt; Node-2A / & gt; & Lt; Node -3 / & gt; & Lt; Node-4 / & gt; & Lt; Node one / & gt;    

"itemprop =" text ">

You can use:

  import Xml node1 /> One & gt; " "" Dom = xml.dom.minidom.parseString (data) node_a = dom.getElementsByTagName ('node one') [0] node_4 = dom.createElement ('node-4') node_a.appendChild (node_4) node_3 = dom. getElementsByTagName ( '  < P> print)> 
  & lt; Node-a & gt; & Lt; Node 1 / & gt; & Lt; Node2 / & gt; & Lt; Node-2A / & gt; & Lt; Node -3 / & gt; & Lt; Node-4 / & gt; & Lt; / Node A & gt;    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -