472,141 Members | 1,391 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,141 software developers and data experts.

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

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,
Jul 18 '05 #1
0 1811

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by bdinmstig | last post: by
2 posts views Thread by Simon John | last post: by
3 posts views Thread by Rupa | last post: by
1 post views Thread by Dan | last post: by
3 posts views Thread by Thierry Lam | last post: by
2 posts views Thread by Carlo, MCP | last post: by
3 posts views Thread by bruce | last post: by
5 posts views Thread by Justin | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.