M
Markus Doering
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="hello" type ="xs:string"/>
The default 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 with the handler, but if you use
namespace aware parsing startElementNS() omits those declarations 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()]) )
results in
NameNone, u'mapping') QName=mapping, Attributes=[]
Should I maybe try another parser than the default one (Expat?)
Thanks for any help,
Markus
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="hello" type ="xs:string"/>
The default 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 with the handler, but if you use
namespace aware parsing startElementNS() omits those declarations 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()]) )
results in
NameNone, u'mapping') QName=mapping, Attributes=[]
Should I maybe try another parser than the default one (Expat?)
Thanks for any help,
Markus