How to get Nokogiri to resolve XPath references when parsing XML?

You can collect location nodes that have actual values (non-reference nodes) and then collect all references separately, as the following snippet demonstrates: require 'nokogiri' xml = 45 -70 End doc = Nokogiri::XML(xml) #Collect all the explicit longitudes longitudes = doc. Search('//locationnot(@reference)/longitude'). Map(&:text) #Follow references to longitudes doc.

Search('//location@reference'). Each do |location| reference = location. Attribute('reference') longitudes "45", "45" You can build on this technique to extract whatever information you want.

I updated the example code. The reference is not an "id" but rather an XPath expression. – Scholle Jan 29 at 19:28 I have updated my answer to handle the XPath expressions.

– Mark Thomas Jan 29 at 23:26 Works nice... thanks for the post @Mark – Scholle Jan 30 at 8:43.

You haven't provided any clue how the second location element references the first. Even if this mechanism were known and we were able to specify it in an XPath expression to select the referenced location element, the selected two longitude nodes would be identical. When an XPath expression is evaluated it always returns a set of nodes -- that is, if the same node is selected more than once it is represented only once in the selection result -- a set doesn't contain duplicate items.

This is why, the longitude element will shows only once in the selection, even though it was selected twice. Here is an example; The XPath expression: /a/* | //c/.. selects only one element be -- not two identical elements b.

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