pyXML beginner questions
Andrew Clover
and-google at doxdesk.com
Mon Mar 15 04:39:56 EST 2004
Sebastian Fey <fey at parsytec.de> wrote:
> actually, is nodetype entityReference implemented in pyXML.
Yes, but you won't ever see them from a parse operation.
Print() will happily serialise an entity reference as &e; providing you
can get one into the document in the first place. Using
Document.createEntityReference() is the only way I know.
> (2) id also like to load external parsed entities referenced in the xml.
> MSXML provides an extension(?) to DOM which returns the uri to an
> entityReference-NODE. any similar in pyXML.
The standard DOM way of doing it is to use the DocumentType.entities
interface:
doctype= entref.ownerDocument.doctype
entdecl= doctype.entities.getNamedItem(entref.nodeName)
uri= entdecl.systemId # see also baseURI if using DOM Level 3 Core
This isn't any use for 4DOM as you won't get any Entity objects from its
parse stage and you can't create your own.
In DOM Level 3 Load/Save, control of whether Entity and EntityReference
objects are kept in the document is achieved with the DOMConfiguration
parameter 'entities':
parser= implementation.createLSParser(1, None)
parser.domConfig.setParameter('entities', True) # False by default
doc= parser.parseURI('file:///in.xml')
serialiser= implementation.createLSSerializer()
serialiser.domConfig.setParameter('entities', True)
serialiser.writeToURI(doc, 'file:///out.xml')
DOM 3 LS is still at Proposed Recommendation stage and isn't supported
by 4DOM yet. (Insert customary pxdom plug here.)
--
Andrew Clover
mailto:and at doxdesk.com
http://www.doxdesk.com/
More information about the Python-list
mailing list