tags:

views:

40

answers:

1

Hi,

I'm trying to do this (using lxml):

//*[@id="32808345" or @id="33771423" or @id="15929470" or @id="33771117" or @id="15929266"]

in order to get all elements, no matter what tag, with the specified id's. I'm getting the following traceback:

invalid attribute predicate

this is how I'm generating the str (if that is relevant to the problem):

refs = ' or '.join('@id="%s"' % ref for ref in refs[0:5])
elements = etree.iterfind('//*[%s]' % refs)

Thanks in advance!

EDIT, with the below solution I'm getting this error:

File "lxml.etree.pyx", line 1201, in lxml.etree._Element.iterchildren (src/lxml/lxml.etree.c:36294)
  File "lxml.etree.pyx", line 2163, in lxml.etree.ElementChildIterator.__init__ (src/lxml/lxml.etree.c:45331)
  File "lxml.etree.pyx", line 2118, in lxml.etree._ElementTagMatcher._initTagMatch (src/lxml/lxml.etree.c:44913)
  File "apihelpers.pxi", line 1413, in lxml.etree._getNsTag (src/lxml/lxml.etree.c:21412)
ValueError: Empty tag name
+2  A: 

The normal way to do this is using the single pipe operator, I believe?

//*[@id="20"] | //*[@id="30"] | ... etc.

Do you have a snippet of the XML you're trying to do this on?

kander
see: http://paste.pocoo.org/show/241242/
ahojnnes
Based on that XML, the above works. Is that what you were looking for?According to http://www.mizar.dk/XPath/Default.aspx using the above with ID's 2 and 7 matches members 2 and 7 in the XML.
kander
ah, ok, you changed your post, now it seems to work.Thank you!
ahojnnes
now I'm getting the above error (edited my original post)
ahojnnes
I'm afraid I can't help with that :/ It looks like a problem with lxml.
kander