473,884 Members | 2,292 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Conte xt import Context
import xml.xpath

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

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

result=xml.xpat h.Evaluate( '//elem/test', d.documentEleme nt )

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.xpat h.Evaluate( '//elem/test', d.documentEleme nt )
File
"/usr/local/lib/python2.3/site-packages/_xmlplus/xpath/__init__.py", line
70, in Evaluate
retval = parser.new().pa rse(expr).evalu ate(con)
File
"/usr/local/lib/python2.3/site-packages/_xmlplus/xpath/ParsedAbbreviat edAbsoluteLocat ionPath.py",
line 44, in evaluate
sub_rt.extend(s elf._rel.select (context))
File
"/usr/local/lib/python2.3/site-packages/_xmlplus/xpath/ParsedRelativeL ocationPath.py" ,
line 23, in evaluate
raise Exception("Expe cted 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.xpat h.Evaluate( 'descendant::el em/test', d.documentEleme nt )

I have the same problem with more complex requests :

Like "//DOC.PRINCIPAL//FILE/@VOL_PAGE_SEQ" that I must rewrite like
"descendant::DO C.PRINCIPAL/descendant::FIL E/@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().pa rse(expr).evalu ate(con)
File
"/usr/local/lib/python2.3/site-packages/_xmlplus/xpath/ParsedAbbreviat edAbsoluteLocat ionPath.py",
line 44, in evaluate
sub_rt.extend(s elf._rel.select (context))
File
"/usr/local/lib/python2.3/site-packages/_xmlplus/xpath/ParsedRelativeL ocationPath.py" ,
line 21, in evaluate
rt = self._left.sele ct(context)
File
"/usr/local/lib/python2.3/site-packages/_xmlplus/xpath/ParsedAbbreviat edRelativeLocat ionPath.py",
line 52, in evaluate
res = Set.Union(res,s ubRt)
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 1936

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
6831
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for elements, attributes, ".", and "..", plus also the "" predicate format is supported - however, only one predicate per path step is supported, and expr must be a relative path. 2. Poor performance
2
1829
by: Simon John | last post by:
I'm sure this must be a PEP, but could someone look at the PyXML documentation? I'm trying to evaluate XML on Python (to eventually use it with XML-RPC) as apposed to Perl. The problem is, I can't find a simple demo or documentation that just says how to create a parser object, and call the start/char/end event handlers.
3
7231
by: Rupa | last post by:
Hi, I'm trying to write an xslt to convert an email in xml format to a new xml format. <descr> <xsl:choose> <xsl:value-of select="body"> </xsl:value-of select> <xsl:when test=" <xsl:value-of select="body/size_in_chars"> > 1042"></xsl:when> <xsl:otherwise> SOMETHING HERE THAT I HAVEN'T SORTED OUT YET
1
1889
by: Dan | last post by:
I'm writing a Python program that does some XML parsing, though nothing heavy, and I want to avoid requiring the user to install additional libraries like PyXML. The documentation for my version of Python (2.3.5) mentions PyXML as an additional library while discussing the DOM module <http://www.python.org/doc/2.3.5/lib/module-xml.dom.html>. I don't seem to have PyXML installed on my system, but: >>> import xml.dom.minidom
3
2414
by: Thierry Lam | last post by:
Let's say I have the following xml tag: <para role="success">1</para> I can't figure out what kind of python xml.dom codes I should invoke to read the data 1? Any help please? Thanks Thierry
2
1395
by: Carlo, MCP | last post by:
Hi, Sorry for posting twice, but I hope in your comprehension. Please help me! I'm troubling from months with a serious serialization problem that I'm not able to solve. I try to describe as simply as I can. 1) I have a class tha does something with colors. All default values are obviously NOT serializad. Instead, they are serialized when they are
3
6809
by: Goran Djuranovic | last post by:
Hi All, Does anyone know how to retreive deepest XPath value from XML document by using VB.NET? For example, if I had an XML file like this: <Root> <Customer> <Name>MyName</Name> </Customer> </Root> I would like to retreive "\Root\Customer\Name" out of it. Something like:
3
2491
by: bruce | last post by:
for guys with python/xpath expertise.. i'm playing with xpath.. and i'm trying to solve an issue... i have the following kind of situation where i'm trying to get certain data. i have a bunch of tr/td... i can create an xpath, that gets me all of the tr.. i only want to get the sibling tr up until i hit a 'tr' that has a 'th' anybody have an idea as to
5
2172
by: Justin | last post by:
Here's my XML: <?xml version="1.0" ?> <AppMode Type="Network"> <CurrentFolder Path="c:\tabs"> <Tabs> <FilePath>tabs\Justin.tab</FilePath> <FilePath>tabs\Julie.tab</FilePath> *****There could be 1 of these or 100....quantity can change***** </Tabs>
0
9953
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9799
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11167
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10868
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10422
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7984
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Duprť who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7137
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5808
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6009
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.