document as child in DOM ??

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


Juliano Freitas wrote:

>I have a document as a string:
>
>xmltext = """<?xml version='1.0'?>
><root>
>	<parara>text</parara>
></root>"""
>
>then i transform the string into a document with fromString method.
>
>i want tu put this "xmltext" as a child to another document called
>"swdb"?
>how can i do this??
>
><swdb>
>  <root>
>	<parara>text</parara>
>  </root>
>...
></swdb>
>
>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" ?>
<root2>


        <root>

   
                <parara>
                        text
                </parara>


        </root>
</root2>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20041102/0d2fa6fd/attachment.html>


More information about the Python-list mailing list