<?standalone yes?>

  • Thread starter Lonnie, SRC employee
  • Start date
L

Lonnie, SRC employee

I can figure out how to set the standalone attribute in the <? xml
version="1.0 ?> tag eg <?xml version="1.0" standalone="yes" ?>

closest I have got to what I need is:
<?xml version="1.0" ?>
<?standalone yes?>
<xpg creator="crusher" version="1.0">
<etr>
<rebmun>

using minidom in this code(snippet):
xmldoc = Document()
pi = xmldoc.createProcessingInstruction("standalone","yes")
xmldoc.appendChild(pi)
xmlroot = xmldoc.createElement("xpg")
xmlroot.setAttribute("version","1.0")
xmlroot.setAttribute("creator","crusher")
xmldoc.appendChild(xmlroot)

thx
Lonnie Souder
 
A

Andrew Clover

Lonnie said:
I can figure out how to set the standalone attribute in the <? xml
version="1.0 ?> tag eg <?xml version="1.0" standalone="yes" ?>

To set this in DOM terms you would need to use the DOM Level 3 Core
property 'xmlStandalone' on the Document object, see:

http://www.w3.org/TR/DOM-Level-3-Core/core.html#Document3-standalone

However, DOM3 is still in Working Draft (though hopefully not for
much longer), and it's not yet supported by minidom. If you don't mind
trying a different DOM implementation, this one supports it:

http://www.doxdesk.com/software/py/pxdom.html
 
P

Peter Hansen

Lonnie said:
I can figure out how to set the standalone attribute in the <? xml
version="1.0 ?> tag eg <?xml version="1.0" standalone="yes" ?>

Simplest approach might be to manually munge the <?xml ?> tag
as you write the output to a file. You could do a simple re.sub()
or something like this, which we've used from time to time with no
ill effects to date (pseudo-code, not executable as-is):

xml = '<?xml version="1.0"?><doc><somestuff/></doc>'

xmlEnd = xml.find('?>') + 2

file.write('<?xml standalone="yes" version="1.0"?>' + xml[xmlEnd:])

In other words, find the end of the original <?xml?> tag, strip it,
substitute your own, continue on with life.

Simplest thing that could possibly work...

-Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,007
Messages
2,570,266
Members
46,863
Latest member
montyonthebonty

Latest Threads

Top