[XML-SIG] SAX: Help on processing qualified attribute values

Markus Döring wixner at web.de
Thu Mar 10 15:17:48 CET 2005


Hey,

I am trying to process XML schema documents using namespace aware SAX 
handlers.
Currently I am using the default python 2.3 parser:

parser = xml.sax.make_parser()
parser.setFeature(xml.sax.handler.feature_namespaces, 1)


At some point I need to parse xml attributes which contain namespace 
prefixes as their value.
For example:

<xs:element name="hallo" type ="xs:string"/>

The SAX parser does a good job on dealing with qualified names as xml 
tags, but is there a way I can access the internal sax mapping between 
prefixes and full namespaces to be able to parse "qualified attribute 
values"? A simple private dictionary prefix2namespace would be 
sufficient.
Or is there a way I can tell the parser to do so for me? I tried to 
keep track of namespace declarations myself in the handler, but if you 
use the namespace aware handlers like startElementNS() those 
declarations are omitted from the resulting attribute list of that 
method.

Parsing the following XML bit:
     <mapping xmlns:dwc="http://www.namespacetbd.org/darwin2" />

Does not produce any attribute with startElementNS()

	def startElementNS(self, name,qname,attrs):
		print "Name:%s QName=%s, 
Attributes=%s"%(unicode(name),unicode(qname), unicode(["%s=%s"%(k,v) 
for k,v in attrs.items()]) )

returns

Name:(None, u'mapping') QName=mapping, Attributes=[]


Should I maybe try another parser than the default one (Expat?)

Thanks for any help,
Markus


--
  Markus Döring
  Botanic Garden and Botanical Museum Berlin Dahlem,
  Dept. of Biodiversity Informatics
  http://www.bgbm.org/BioDivInf/


More information about the XML-SIG mailing list