Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > SAX: Help on processing qualified attribute values

Reply
Thread Tools

SAX: Help on processing qualified attribute values

 
 
Markus Doering
Guest
Posts: n/a
 
      03-10-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_namespac es, 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


--
Markus Döring
Botanic Garden and Botanical Museum Berlin Dahlem,
Dept. of Biodiversity Informatics
http://www.bgbm.org/BioDivInf/
 
Reply With Quote
 
 
 
 
Uche Ogbuji
Guest
Posts: n/a
 
      03-23-2005
On Thu, 2005-03-10 at 15:22 +0100, Markus Doering wrote:
> 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_namespac es, 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.


Just for others, this was answered here:

http://mail.python.org/pipermail/xml...ch/010989.html

I also provide a useful mix-in class for this purpose in Amara's
saxtools:

http://www.xml.com/pub/a/2005/01/19/amara.html
http://cvs.4suite.org/viewcvs/Amara/....9&view=markup

In the latter link see class namespace_mixin, which you should be
able to copy to your code if you don't want to install Amara).


--
Uche Ogbuji Fourthought, Inc.
http://uche.ogbuji.net http://4Suite.org http://fourthought.com
Use CSS to display XML, part 2 - http://www-128.ibm.com/developerwork...xmlcss2-i.html
Introducing the Amara XML Toolkit - http://www.xml.com/pub/a/2005/01/19/amara.html
Gems from the Mines: 2002 to 2003 - http://www.xml.com/pub/a/2005/03/02/pyxml.html
Be humble, not imperial (in design) - http://www.adtmag.com/article.asp?id=10286
Querying WordNet as XML - http://www.ibm.com/developerworks/xm...x-think29.html
Packaging XSLT lookup tables as EXSLT functions - http://www.ibm.com/developerworks/xm...-tiplook2.html

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pointer to qualified poitner to qualified object Szabolcs Borsanyi C Programming 13 06-08-2008 07:52 PM
JNDI: Delete only one attribute when there are several different values for the same attribute bsporb@gmail.com Java 3 05-02-2007 05:41 AM
Help with embedding fully qualified script name Jim Wallace Python 1 02-14-2005 02:06 PM
Post-Processing RAW vs Post-Processing TIFF Mike Henley Digital Photography 42 01-30-2005 08:26 AM
Question: processing HTML, re-write default processing action of many tags Hubert Hung-Hsien Chang Python 2 09-17-2004 03:10 PM



Advertisments