document as child in DOM ??

Jeremy Jones zanesdad at
Tue Nov 2 19:10:45 CET 2004

Juliano Freitas wrote:

>I have a document as a string:
>xmltext = """<?xml version='1.0'?>
>	<parara>text</parara>
>then i transform the string into a document with fromString method.
>i want tu put this "xmltext" as a child to another document called
>how can i do this??
>  <root>
>	<parara>text</parara>
>  </root>
>i tryed the importNode and appendNode, but i dont if i'm doing right!
>Juliano Freitas
How about something like this:

In [30]: x1
Out[30]: "<?xml version='1.0'?>\n<root>\n    <parara>text</parara>\n</root>"

In [31]: x2
Out[31]: "<?xml version='1.0'?>\n<root2>\n</root2>"

In [32]: d1 = minidom.parseString(x1)

In [33]: d2 = minidom.parseString(x2)

In [34]: d2.documentElement.appendChild(d1.documentElement)
Out[34]: <DOM Element: root at 0xf6b0d4ac>

In [35]: print d2.toprettyxml()
<?xml version="1.0" ?>




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list