Why doesn't Nokogiri xpath like xmlns declarations?

That XPath query looks for elements that are not in any namespace. You need to tell your XPath processor that you are looking for elements in namespace sdb.amazonaws.com/doc/2007-11-07 One way to do that with nokogiri is this: doc = Nokogiri::XML. Parse(...) doc.

Xpath("//aws:Item/aws:AttributeName='Foo'/aws:Value", {"aws" => "sdb.amazonaws.com/doc/2007-11-07/"}).

That XPath query looks for elements that are not in any namespace. You need to tell your XPath processor that you are looking for elements in namespace sdb.amazonaws.com/doc/2007-11-07/ One way to do that with nokogiri is this: doc = Nokogiri::XML. Parse(...) doc.

Xpath("//aws:Item/aws:AttributeName='Foo'/aws:Value", {"aws" => "sdb.amazonaws.com/doc/2007-11-07/"}).

That's fixed it. Thank you. – Mark Rendle Nov 15 '09 at 15:45.

I found this really helpful in understanding what's going on: tenderlovemaking.com/2009/04/23/namespac... Basically if you have a namespace defined at all (via xmlns=), you must use a namespace in your xpath searches. So in your case, you could do one of three things: Remove the xmlns attribute from the root SearchResponse. In that case your original, namespace-less xpath query will work.

Use the default namespace in your xpath query doc/"//xmlns:Item/xmlns:Attributexmlns:Name='Foo'/xmlns:Value" Define a custom namespace in the second argument of the xpath method call and use that in your query, as shown in hrnt's solution above.

There's a remove_namespaces! Method documented here. – RobinGower Oct 4 at 22:17.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions