Querying xml row by attribute

I have a csv file that I will be using to retrieve values from. Using the csv to xml module i am returned a series of lines with a set of attributes each for each column value like so

<line Report="Account Summary" Description="ADVANCE PURCHASE 2.9% DISCOUNT (NET column)" HTDALIV="2260 Reservations" HTDFWGP="2260 Reservations" HTDFWNL="2260 Reservations" HXFTWTC="2260 Reservations"/>
<line Report="Account Summary" Description="ROOM UPGRADE ALLOWANCE (NET column)" HTDALIV="2000-000 Rooms Revenue" HTDFWGP="2000-000 Rooms Revenue" HTDFWNL="2000-000 Rooms Revenue" HXFTWTC="2000-000 Rooms Revenue"/>
<line Report="Account Summary" Description="TELEPHONE ALLOWANCE (NET column)" HTDALIV="5515 Other" HTDFWGP="5515 Other" HTDFWNL="5515 Other" HXFTWTC="5515 Other"/>

What I would ideally like to do is be able to query against that, something like…
"select HTDALIV where Report = ‘Account Summary’ and Description = ‘TELEPHONE ALLOWANCE (NET column)’ so it then returns the value "5515 Other’. (this is all from the 3rd row for example).

Is there a clean way to do that? I did not see anything in the vtd doc to handle that. Not sure if you know of another way.

Thanks

Something like this should work:

element.selectNodes("//line[@Report=‘something’ and @Description=‘something’]")

See https://stackoverflow.com/questions/2009268/how-to-write-an-xpath-query-to-match-two-attributes

ok, then i could just pass in the values of what im querying against and what data i need as arguements… ok i think that would work. thanks

Also, be sure to escape any embedded single quotes within the search text.

Maybe this will help: https://stackoverflow.com/questions/13482352/xquery-looking-for-text-with-single-quote

1 Like