Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
xml_select and namespaces
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Adam Olsen  
View profile  
 More options Jul 19 2009, 12:29 pm
From: Adam Olsen <arol...@gmail.com>
Date: Sun, 19 Jul 2009 09:29:42 -0700 (PDT)
Local: Sun, Jul 19 2009 12:29 pm
Subject: xml_select and namespaces
Given the following XML:

<?xml version="1.0" encoding="UTF-8"?>
<user xmlns="urn:goonswarm:core:1" id="4514099">
        <api-keys>
                <api-key type="limited" href="http://localhost:1521/api/1/api-keys/
1/"/>
         </api-keys>
</user>

How can I select the href attribute using xml_select?

doc.xml_select(u'user/api-keys/api-key/@href') selects nothing, I
believe it's because of the namespace


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Uche Ogbuji  
View profile  
 More options Jul 19 2009, 1:12 pm
From: Uche Ogbuji <u...@ogbuji.net>
Date: Sun, 19 Jul 2009 11:12:17 -0600
Local: Sun, Jul 19 2009 1:12 pm
Subject: Re: xml_select and namespaces

Yep.  It's is an XPath FAQ.

http://xml3k.org/Amara/FAQ#XPath.28e.g.xmlxpathmethod.29andXSLTpatter...

That recipe I need to update that FAQ for Amara 2, but this should help:

XML = """<?xml version="1.0" encoding="UTF-8"?>
<user xmlns="urn:goonswarm:core:1" id="4514099">
       <api-keys>
               <api-key type="limited" href="
http://localhost:1521/api/1/api-keys/
1/"/>
        </api-keys>
</user>"""

from amara.bindery import parse #Doesn't yet work for non-bindery parse.
We're thinking about this
doc = parse(XML, prefixes={'ns': 'urn:goonswarm:core:1'})
print doc.xml_select(u'ns:user/ns:api-keys/ns:api-key/@href')[0].xml_value

#For non-bindery parse:

from amara import parse
doc = parse(XML)
PREFIXES = {'ns': 'urn:goonswarm:core:1'}
print doc.xml_select(u'ns:user/ns:api-keys/ns:api-key/@href',
prefixes=PREFIXES)[0].xml_value

--
Uche Ogbuji                       http://uche.ogbuji.net
Founding Partner, Zepheira        http://zepheira.com
Linked-in profile: http://www.linkedin.com/in/ucheogbuji
Articles: http://uche.ogbuji.net/tech/publications/
friendfeed: http://friendfeed.com/uche
Join me at STC09:
* http://www.semantic-conference.com
* http://friendfeed.com/stc09


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »