473,379 Members | 1,253 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,379 software developers and data experts.

pyXML beginner questions



hi,

id like to do the following:

(1) open a .xml, change something and save it.
problem is: how to save/serialize?
i tried xml.dom.ext.Print, but this resolves all entities and serializes
the xml with resolved entities. (see example below)

(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. actually, is nodetype entityReference implemented
in pyXML. i always get the nodeType of the resolved entity, ie 3
(NODE_TEXT) with a internal unparsed entity.
#############
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE xbel [
<!ENTITY intTxt 'GIGI'>
<!ENTITY intMarkup '<entIntern>text</entIntern>'>
<!ENTITY extParsed SYSTEM "ent.xml">
]>
<root>
<text>&intTxt;</text>
&intMarkup;
&extParsed;
</root>
############

becomes:

#############
<?xml version="1.0" encoding="iso-8859-1"?>
<root>
<text>some text</text>
<entIntern>text</entIntern>'
<entIntern>text</entIntern>'
</root>
#############

thx,
Sebastian


Jul 18 '05 #1
2 2005
Sebastian Fey <fe*@parsytec.de> wrote in message news:<c2*************@ID-190842.news.uni-berlin.de>...
hi,

id like to do the following:

(1) open a .xml, change something and save it.
problem is: how to save/serialize?
i tried xml.dom.ext.Print, but this resolves all entities and serializes
the xml with resolved entities. (see example below)
Sounds as if you want a lexical round-trip. Very few XML processing
packages allow for this. I'd check whether pxdom supports this. If
not, I don't expect you'll find it in Python.

http://www.doxdesk.com/software/py/pxdom.html
(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. actually, is nodetype entityReference implemented
in pyXML. i always get the nodeType of the resolved entity, ie 3
(NODE_TEXT) with a internal unparsed entity.


Again pxdom will get you closest.

--Uche
Jul 18 '05 #2
Sebastian Fey <fe*@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:an*@doxdesk.com
http://www.doxdesk.com/
Jul 18 '05 #3

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

Similar topics

0
by: leo | last post by:
hi there i want to write a little SOAP client and thought about using ZSI. now i have read that ZSI only works with PyXML versions later than 0.6 and earlier than 0.7. unfortunaltly i can...
2
by: David Dorward | last post by:
I'm attempting to read an XHTML 1.1 file, perform some DOM manipulation, then write the results to a different file. I've found myself rather stuck at the first hurdle. I have the following: ...
1
by: Alain | last post by:
Hi ! I'm looking for an XPath implementation (even partial) on PyXML. I'm using libxml2 on Windows XP. It works well but I have to port my application on RISCOS (OS on ARM processor) where only...
2
by: Stefan Behnel | last post by:
Hi! I'm using PyXML 0.8.3 on a number of machines. When I now run import xml.sax.saxlib python touches both the python/xml/sax and python/site-packages/_xmlplus modules but not _xmlplus/sax...
1
by: Dan | last post by:
I'm writing a Python program that does some XML parsing, though nothing heavy, and I want to avoid requiring the user to install additional libraries like PyXML. The documentation for my version...
1
by: PyPK | last post by:
How do I add a new attribute to the existing xml Document tree???
5
by: Matthias Kaeppler | last post by:
Hi, I have to say I am confused about the documentation on pyxml.sf.net. When I want to use DOM, I effectively am using a class called Sax2? ^^ I also have to catch SAXExceptions, which reside...
3
by: Thomas W | last post by:
I've tried to install the pyxml-package, available at http://pyxml.sourceforge.net/, both from source and using some hack on the win32-binary package available for python2.4, but without luck....
4
by: kdwyer | last post by:
Hello Everyone, I've been looking into writing a utility to compare/analyse xml files, and thought I'd have a look at PyXml, but the Sourceforge page says it's no longer maintained. Two...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...

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.