Complex Searching XML

33 views
Skip to first unread message

Corey Vincent

unread,
Mar 5, 2018, 10:18:50 AM3/5/18
to nokogiri-talk
I'm trying to search something like this:

<main>
<subMain>
<attribute>
<attributeName>Bob</attributeName>
</attribute>
<attributeValue>3</attributeValue>
</subMain>
<subMain>
<attribute>
<attributeName>Sarah</attributeName>
</attribute>
<attributeValue>31</attributeValue>
</subMain>
</main>

Where I want to get the `<attributeValue>` for the `<attributeName>` that is "Sara".

Mike Dalessio

unread,
Mar 5, 2018, 10:22:55 AM3/5/18
to nokogiri-talk
Hi Corey,

Can you share what code you've written so far? Generally I've found that the list can be more helpful when we're iterating on an existing, if incomplete, solution, rather than guessing at a complete solution for you.

--
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-talk+unsubscribe@googlegroups.com.
To post to this group, send email to nokogi...@googlegroups.com.
Visit this group at https://groups.google.com/group/nokogiri-talk.
For more options, visit https://groups.google.com/d/optout.

Ryan Rickerts

unread,
Mar 30, 2018, 2:08:35 PM3/30/18
to nokogiri-talk
Corey,

I have done something like this in XQuery on a native XML database. It looks a bit like this, where your XML is saved as 'sample.xml'. This presumes no namespaces in the file.

let $main:=doc('sample.xml')
let $subMain
:=$main/subMain
for $attr in $subMain/
where $attr/attributeName='Sarah'
return $attr/../attributeValue


Reply all
Reply to author
Forward
0 new messages