Re: [nokogiri-talk] Cannot access namespaced attribute?

29 views
Skip to first unread message

Mike Dalessio

unread,
May 8, 2013, 8:56:53 AM5/8/13
to nokogiri-talk
Hello!

Can you please reply with a code that reproduces the behavior you think Nokogiri should demonstrate?

Thanks so much!

-mike



On Wed, May 8, 2013 at 8:51 AM, Christoph Blank <ch.b...@gmail.com> wrote:
Hi there,

If I have an element like this:

#<Nokogiri::XML::Element:0x1650b48 name="title" namespace=#<Nokogiri::XML::Namespace:0x169160c prefix="dc" href="http://purl.org/dc/elements/1.1/"> attributes=[#<Nokogiri::XML::Attr:0x1650ad0 name="lang" namespace=#<Nokogiri::XML::Namespace:0x16502b0 prefix="xml" href="http://www.w3.org/XML/1998/namespace"> value="EN">] children=[#<Nokogiri::XML::Text:0x163fc6c "Austria">]>

Shouldn't e['lang'] return the lang attribute?

Thanks a lot,
Christoph

--
You received this message because you are subscribed to the Google Groups "nokogiri-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nokogiri-tal...@googlegroups.com.
To post to this group, send email to nokogi...@googlegroups.com.
Visit this group at http://groups.google.com/group/nokogiri-talk?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Christoph Blank

unread,
May 8, 2013, 8:59:29 AM5/8/13
to nokogi...@googlegroups.com
Thanks for your reply Mike.

This is the XML:
<geo:Countries xmlns:geo="http://schema.seekda.com/geo"
  xsi:schemaLocation="http://schema.seekda.com/geo geo.xsd">
  <geo:Country isoCode="AT">
    <dc:title xml:lang="EN">Austria</dc:title>
  </geo:Country>                                                                                                                              
</geo:Countries>

For the above, unfortunately I don't have more code currently as this is nokogori used inside the happymapper library.
I just inspected the element and saw that the attribute 'lang' is actually there as a Nokogiri object, but that it is not returned with ['lang'] - I have no idea why...
Is there something that prevents this? Or did I misunderstand how to access attributes?

Thanks,
Christoph

Ben Langfeld

unread,
May 8, 2013, 9:58:45 AM5/8/13
to nokogi...@googlegroups.com
node['xml:lang'] should do you fine. This is similar behaviour to more or less every other major XML parser that exists, and how the JRuby implementation of Nokogiri has worked for a long time. The libxml implementation was fixed in 1.5.something at my request to match. It should be in the changelog somewhere.

Regards,
Ben Langfeld

Jonathan Rochkind

unread,
May 8, 2013, 10:16:30 AM5/8/13
to nokogi...@googlegroups.com
Namespaced attributes are _really_ confusing (as if namespaced elements
weren't confusing enough).

I'm not entirely sure what the 'correct' behavior is, and would urge
caution in making a potentially backwards-incompat change based on one
use case.

First to figure out what's going on now exactly, what happens if you
have ask for e.attributes, what do you get?
> <http://groups.google.com/group/nokogiri-talk?hl=en>.
> For more options, visit https://groups.google.com/groups/opt_out
> <https://groups.google.com/groups/opt_out>.

Christoph Blank

unread,
May 8, 2013, 10:16:59 AM5/8/13
to nokogi...@googlegroups.com, b...@langfeld.me
Ah! I didn't try that :/
Thanks a lot!

Mike Dalessio

unread,
May 10, 2013, 8:50:36 AM5/10/13
to nokogiri-talk


On May 8, 2013 8:59 AM, "Christoph Blank" <ch.b...@gmail.com> wrote:
>
> Thanks for your reply Mike.
>
> This is the XML:
> <geo:Countries xmlns:geo="http://schema.seekda.com/geo"
>   xmlns:dc="http://purl.org/dc/elements/1.1/
>   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>   xsi:schemaLocation="http://schema.seekda.com/geo geo.xsd">
>   <geo:Country isoCode="AT">
>     <dc:title xml:lang="EN">Austria</dc:title>
>   </geo:Country>                                                                                                                              
> </geo:Countries>
>
> For the above, unfortunately I don't have more code currently as this is nokogori used inside the happymapper library.

I can tell you how to do this using the Nokogiri API, but it sounds like that won't help you, since you're using another gem.

How can I help you?

Reply all
Reply to author
Forward
0 new messages