473,395 Members | 1,885 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

tag replacement in toxml()

Hi all,

I am new on the list and I already have a question :-(.

Ihave something like this:

import xml.dom.minidom
from xml.dom.minidom import getDOMImplementation
impl = getDOMImplementation()
myDoc = impl.createDocument(None, "example", None)
myRoot = myDoc.documentElement
myNode1 = myDoc.createElement("node")
myNode2 = myDoc.createElement("nodeTwo")
myText = myDoc.createTextNode("Here is the <b>problem</>")
myNode2.appendChild(myText)
myNode1.appendChild(myNode2)
myRoot.appendChild(myNode1)
print myDoc.toxml()

The result is:
'<?xml version="1.0" ?>\n<example><node><nodeTwo>Here is the &lt;b&gt;problem&lt;/&gt;</nodeTwo></node></example>'
My question is how I can avoid that toxml() replaces the tags?

Regards,
Manuel



______________________________________________
LLama Gratis a cualquier PC del Mundo.
Llamadas a fijos y móviles desde 1 céntimo por minuto.
http://es.voice.yahoo.com
Apr 1 '07 #1
1 1132
import xml.dom.minidom
from xml.dom.minidom import getDOMImplementation
impl = getDOMImplementation()
myDoc = impl.createDocument(None, "example", None)
myRoot = myDoc.documentElement
myNode1 = myDoc.createElement("node")
myNode2 = myDoc.createElement("nodeTwo")
myText = myDoc.createTextNode("Here is the <b>problem</>")
myNode2.appendChild(myText)
myNode1.appendChild(myNode2)
myRoot.appendChild(myNode1)
print myDoc.toxml()

The result is:
'<?xml version="1.0" ?>\n<example><node><nodeTwo>Here is the &lt;b&gt;problem&lt;/&gt;</nodeTwo></node></example>'
My question is how I can avoid that toxml() replaces the tags?
Gabriel already answered the question: you need to add a 'b'
element, which has a text child with the text 'problem'; this
b element needs to be a sibling of the text node 'Here is the '.

This still won't give you the output "Here is the <b>problem</>",
as that will insert a closing tag. If you really want to produce
the text

'<?xml version="1.0" ?>\n<example><node><nodeTwo>Here is the
<b>problem</></nodeTwo></node></example>'

you cannot use an XML library to do so: this text is not
well-formed XML (because </is illegal syntax).

Regards,
Martin
Apr 1 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Paul Miller | last post by:
We've run into minidom's inabilty to handle large (20+MB) XML files, and need a replacement that can handle it. Unfortunately, we're pretty dependent on a DOM, so a pulldom or SAX replacement is...
3
by: Ray | last post by:
I have put together some pretty simple code for adding and removing elements from an XML file, but am having a problem with toxml writing out the correct format after I have called appendChild on a...
53
by: Kerberos | last post by:
I followed Dan Cederholm's image replacement tutorial, to replace a header tag by a logo. The h1 is clickable if no CSS is applied but it I replace it by the logo, the area isn't clickable anymore...
3
by: Vibha Tripathi | last post by:
Hi Folks, I put a Regular Expression question on this list a couple days ago. I would like to rephrase my question as below: In the Python re.sub(regex, replacement, subject)...
2
by: brian | last post by:
Hi, before coming to .NET, I utilized regular expressions mostly in JScript / JavaScript and also in my favorite text editor: TextPad (www.textpad.com) I don't know about JScript/JavaScript, but...
20
by: Paul D. Boyle | last post by:
Hi all, There was a recent thread in this group which talked about the shortcomings of fgets(). I decided to try my hand at writing a replacement for fgets() using fgetc() and realloc() to read...
3
by: Jeffrey D. Gordon | last post by:
I'm wanting to replace Field Values in an existing PDF, I've done this with PHP by doing a replace in the file. I've been able to read the file in a byte array in c# but all my attempts to...
1
by: lawrence k | last post by:
Want to replace the limit clause in a query, but can't get it right. What's wrong with this: $pattern = "(.*)limit (.*)"; $replacement = '$1'; $replacement .= "LIMIT $limit"; $replacement .=...
3
by: =?Utf-8?B?RHVrZSAoQU4yNDcp?= | last post by:
I've added a web deployment project and want to use the config section replacement but I'm obviously not understanding something. I have set up an alternate appSettings file,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.