I’ve been using the css function from nokogiri to navigate xml and grab elements, instead of using xpath. I love the fact that it’s an option, since css feels to much more natural. But, today I ran into something I haven’t had to deal with before. I was parsing some xml from a service when I noticed the xml had some namespaced items, like so.
<xml>
<blah:item1>some text</blah:item1>
<blah:item2>more stuff</blah:item2>
</xml>
So, I tried this, thinking I could get the value back.
node.css("blah:item1")
But, no luck. However, as it turns out, there is a special selector made just for this. Here is the reference on w3.org. The correct code is below:
node.css("blah|item1")