I have the following XML, I am trying to get unique nodes based on the name of the child node.
Original XML:
<products>
<product>
<name>White Socks</name>
<price>2.00</price>
</product>
<product>
<name>White Socks/name>
<price>2.00</price>
</product>
<product>
<name>Blue Socks</name>
<price>3.00</price>
</product>
</products>
What am I trying to get:
<products>
<product>
<name>White Socks</name>
<price>2.00</price>
</product>
<product>
<name>Blue Socks</name>
<price>3.00</price>
</product>
</products>
I tried different things, but not worth listing here, the closest I got was using XPath, but it just returned the names as shown below. However, this is not true since I want all of the XML to be listed above, and not just the node values.
White Socks
Blue Socks
I am using Ruby and trying to iterate over the following nodes:
@doc.xpath("//product").each do |node|
Obviously, the above is currently getting ALL product nodes, while I want all the unique nodes of the product (using the child node "name" as a unique identifier)
source
share