[XML-SIG] XML to XML Conversation via SAX
Jörg Kantel
kantel@mpiwg-berlin.mpg.de
Tue, 3 Aug 1999 17:38:04 +0200
(maybe a very stupid question ;-)
We have a collection of (very) large XML files that we have to convert to
XML files. That sounds stupid but we have to insert or to update in
different tags attributes concerning on the contents of the files.
I thought I could do that with Python and the saxlib but I run in a problem
by writing the attributes back (in other words: I'm to stupid to use the
saxlib.AttributeList-methods. I tried the following (mostly inspired by the
saxlib tutorial ;-)
#!usr/local/bin/python
from xml.sax import saxlib
import string
class WriteTags(saxlib.HandlerBase, saxlib.AttributeList):
def makeStartTag(self, name):
tagText = "<" + name
numbers = saxlib.AttributeList().getLength()
print numbers
if numbers:
for i in numbers:
tagName = saxlib.AttributeList().getName(i)
tagValue = saxlib.AttributeList().getValue(i)
print tagName
print tagValue
tagText = tagText + " " + tagName + "=\"" + tagValue + "\" "
tagText = tagText + ">"
return tagText
(...)
makeStartTag was called in the startElement-method, but numbers (and
therefore tagName and tagValue too) returns always "none". I'm really not
sure how to connect the AttributeList-methods with the HandlerBase. Any
hints are wellcome.
TIA
J"org
--
--------------------------------------------------------------------------
J"org Kantel Max-Planck-Institute for the History of Science
Computer-Department kantel@mpiwg-berlin.mpg.de
Wilhelmstr. 44 http://www.mpiwg-berlin.mpg.de/staff/kantel/kantel.html
D-10117 Berlin fon: +4930-22667-220 fax: +4930-22667-299
--------------------------------------------------------------------------