I'm looking for help with PyXML and XPath : simple Path expressionseems to crash with brutality

G

gael.pegliasco

Hi,

How are you dear and nice helper :) ?

I'm trying to test xpath with this simple program :

import xml.dom.minidom
from xml.xpath.Context import Context
import xml.xpath

s = '''<?xml version="1.0"?>
<root>
<elem attr="1">Some<test>roto</test> text</elem>
<elem attr="2">More text</elem>
</root>'''

d = xml.dom.minidom.parseString(s)

result=xml.xpath.Evaluate( '//elem/test', d.documentElement )

for node in result:
print node, node.nodeName

But it crashed with the message below:

-- <Error message> --
Traceback (most recent call last):
File "./xpath.py", line 12, in ?
result=xml.xpath.Evaluate( '//elem/test', d.documentElement )
File
"/usr/local/lib/python2.3/site-packages/_xmlplus/xpath/__init__.py", line
70, in Evaluate
retval = parser.new().parse(expr).evaluate(con)
File
"/usr/local/lib/python2.3/site-packages/_xmlplus/xpath/ParsedAbbreviatedAbsoluteLocationPath.py",
line 44, in evaluate
sub_rt.extend(self._rel.select(context))
File
"/usr/local/lib/python2.3/site-packages/_xmlplus/xpath/ParsedRelativeLocationPath.py",
line 23, in evaluate
raise Exception("Expected node set from relative expression. Got
%s"%str(rt))
Exception: Expected node set from relative expression. Got ()
-- </Error message> --


If I try with this syntax, its works :
result=xml.xpath.Evaluate( 'descendant::elem/test', d.documentElement )

I have the same problem with more complex requests :

Like "//DOC.PRINCIPAL//FILE/@VOL_PAGE_SEQ" that I must rewrite like
"descendant::DOC.PRINCIPAL/descendant::FILE/@VOL_PAGE_SEQ" else it
crashed with
a different message :

-- <Error message> --
Traceback (most recent call last):
File
"/edika/vol1/users/gpegliasco/projets/dev/tools/src/xpathgrep.py", line
233, in ?
searchInFile( file, searchedObject )
File
"/edika/vol1/users/gpegliasco/projets/dev/tools/src/xpathgrep.py", line
77, in searchInFile
listNodes = xpath.Evaluate( xpathquery, context=con )
File
"/usr/local/lib/python2.3/site-packages/_xmlplus/xpath/__init__.py", line
70, in Evaluate
retval = parser.new().parse(expr).evaluate(con)
File
"/usr/local/lib/python2.3/site-packages/_xmlplus/xpath/ParsedAbbreviatedAbsoluteLocationPath.py",
line 44, in evaluate
sub_rt.extend(self._rel.select(context))
File
"/usr/local/lib/python2.3/site-packages/_xmlplus/xpath/ParsedRelativeLocationPath.py",
line 21, in evaluate
rt = self._left.select(context)
File
"/usr/local/lib/python2.3/site-packages/_xmlplus/xpath/ParsedAbbreviatedRelativeLocationPath.py",
line 52, in evaluate
res = Set.Union(res,subRt)
File "/usr/local/lib/python2.3/site-packages/_xmlplus/xpath/Set.py",
line 25,
in Union
return compare + filter(lambda x,compare = compare:x not in
compare,loop)
TypeError: can only concatenate list (not "tuple") to list
-- </Error message> --

Does someone know what's wrong with these requests ?

Is it a bad use from me or a bug or something else with PyXML ?

Thanks you very much for your help,

With kind regards,

Gaël,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,149
Members
46,695
Latest member
StanleyDri

Latest Threads

Top