473,326 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

xpath question...

hi...

i have the following section of test code where i'm trying to get the
attribute of a frame
<frame src="....">

i'm trying to print/get the src value. the xpath query that i have displays
the "src" attribute in the Xpather/Firefox plugin. however, i can't quite
figure out how to get the underlying value in my test app...

sxpath = "/html/frameset/frame[2]/attribute::src"
# s contains HTML not XML text
d = libxml2dom.parseString(s, html=1)

#get the tr list
tr1 = d.xpath(sxpath)

url = tr1[0]

#get the url/link >>semester page
#link = br.find_link(nr=1)

#url = link.url
print "link = ",url
sys.exit()

err output
link = <libxml2dom.Attribute object at 0xb7b7680c>

--------------------------------------

i'm not sure what i need to add to the line
url = tr1
to resolve the issue/error...

looking over google hasn't given any real pointers...
thanks

-bruce
Jul 9 '06 #1
1 1645
"bruce" <be*******@earthlink.netwrites:
i have the following section of test code where i'm trying to get the
attribute of a frame
<frame src="....">

i'm trying to print/get the src value. the xpath query that i have displays
the "src" attribute in the Xpather/Firefox plugin. however, i can't quite
figure out how to get the underlying value in my test app...

sxpath = "/html/frameset/frame[2]/attribute::src"
# s contains HTML not XML text
d = libxml2dom.parseString(s, html=1)

#get the tr list
tr1 = d.xpath(sxpath)

url = tr1[0]

#get the url/link >>semester page
#link = br.find_link(nr=1)

#url = link.url
print "link = ",url
sys.exit()

err output
link = <libxml2dom.Attribute object at 0xb7b7680c>

--------------------------------------

i'm not sure what i need to add to the line
url = tr1
to resolve the issue/error...
It *looks* like "err output" is just a string you typed into your
message? If so, that's not "an error" in the usual sense (there's no
traceback): rather, it's just output you didn't expect.

When somebody what you wrote, though, they must go through the
following laborious thought process: Is that string part of the
literal text output by your program, or are you indicating that you
saw a traceback that contains the following line ("link = ...")? Or
is it something you just typed in to your message to indicate that the
result is unexpected to you? If there's a traceback, post the full
traceback. If that is the literal output, you should say so
explicitly, or make it clear through copy/paste of a shell session:

"""
$ my-test-prog.py
err output
link = <libxml2dom.Attribute object at 0xb7b7680c>
$
"""

Back to your problem: The output is not unexpected, though (though I
don't know libxml2dom). First, if you're bent on using XPath, you may
be better off with module lxml, which I think is a more recent and
friendlier wrapper of libxml2 / libxslt. Second, you're almost there:
you're just getting back an object representing the attribute, rather
than the string you're looking for. You simply need to ask the object
for its string representation. How that's done depends on the module,
but it looks like you have to call a method explicitly in this case (I
can't find the libxml2dom docs easily).
John
Jul 9 '06 #2

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

Similar topics

7
by: Sebastian Petzelberger | last post by:
Hi group, please give me an example of a xpath with regex or better a link with examples. Thanks in advance, Sebastian
0
by: Bart | last post by:
Hello, I am real new to using LIBXML and have a question about XPATH evaluations. The question may show a real ignorance of the LIBXML structure, don't so assume I know what I am talking about....
3
by: Kathy Burke | last post by:
Hi again, I'm using the following xpath (works in visualizer) with a SelectSingleNode("xpath") statement. //Station/(WI])]/@order Problem is I get an error "expression passed to this method...
2
by: ree32 | last post by:
When I import an xml document in Visual studio and Genereate as schema from it, and create a dataset from it, it adds this line into to the root element of my xml file -...
9
by: David Thielen | last post by:
Hi; I am sure I am missing something here but I cannot figure it out. Below I have a program and I cannot figure out why the xpath selects that throw an exception fail. From what I know they...
5
by: Gnic | last post by:
Hi , I have an XmlDocument instance, I want to find a node in the xml, but I don't know it's path until runtime, for example <aaa> <bbb name="x"/> <aaa attr="y"> <ccc>sometext</ccc> </aaa>
7
by: Tim Hallwyl | last post by:
Hi, there! As I understand the XPaht recommendation, the context node is a node; not a node-list, not XPath object -- but a single node. Now, the WS-BPEL 2.0 specification allows an XML simple...
0
by: pompair | last post by:
Hello, I'm making a quiz game for fun. I have an xml file like this: <?xml version="1.0" encoding="utf-8" ?> <results> <index>99</index> <answers>11</answers> <questions> <question id="1">
0
by: John Krukoff | last post by:
On Wed, 2008-09-03 at 13:36 -0700, bruce wrote: Well, you could just do the test (and the count!) in the xpath expression: count( //tr/td ) It sounds like you're not familiar with xpath? I...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.