0

I have a list of about 950 integers in a CSV file and an XML file containing complexly nested info (each entry contains multiple nests). Given an integer, i, in the CSV file, each i corresponds to an i in the XML file: i in <entry><key>i</key>. I would like to extract a pre-specified set of columns from the XML file for each i listed in the CSV file.

Here is an example of a set of extraction 'columns', for lack of a better word (targets are surrounded by double asterisks):

<entry>
<key>55</key>
<cd language="**en**">
  <title>**Ride The Lightning**</title>
  <band>Metallica</band>
</cd>
<tabbook language="**en**">
  <title>**Ride The Lightning Tab**</title>
  <author>Who J. Ever</author>
</tabbook>
</entry>

Should I just load the CSV file's values into a variable in a script, or is there an existing and better way to do this?

Edit:

Presently I'm trying to use BaseX. For a starter query, I'm trying: for $e in collection("catalog")//entry where //entry/cd/title contains text "lightning" return //title, which I take to mean (or rather hope means): for a "entry"-titled tag that is the descendant of any tag in the "collection"-titled catalog, if that same entry's "cd"-titled descendant's "title"-titled descendant contains the text "lightning", echo back to me the full title.

Damn, that's confusing.... I have been told to use concat() rather than return. The query seems to be incorrect. I'll continue to study and post again when I've come up with proper grammar.

Wolfpack'08
  • 3,982
  • 11
  • 46
  • 78
  • I was thinking about changing the delimiter from `,` to `||` or `or` and then copying and pasting the entire string into some kind of query.... Alternatively, using a program like fxgrep? – Wolfpack'08 Sep 13 '12 at 15:15

1 Answers1

0

With XPath (at least with XPath2) you can use a query like

 //entry[key = (1,2,3,4,5)]

to find all entries with a key in (1,2,3,4,5).

Then just paste your CSVs in the parenthesis

BeniBela
  • 16,412
  • 4
  • 45
  • 52
  • But what if you only want to get a specified set of descendants from each of those keys? For example, you want to get the artist name and the first two CD titles, only. You do not want to get the drummer's name, the third CD title, or any of the other info? – Wolfpack'08 Sep 14 '12 at 00:20