473,671 Members | 2,568 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.pars eString(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.Att ribute 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 1657
"bruce" <be*******@eart hlink.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.pars eString(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.Att ribute 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.Att ribute 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
16649
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
1282
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. I am trying to use the XPATH functions to pull the data for individual data elements. The order of the elements whose value I must find are not necessarily contiguous in the XML document. So walking the tree will not work.
3
4538
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 should result in a NodeSet". Of course, that (sort of) makes sense to me now (I suppose just an attribute couldn't be a nodeset, but how would I go
2
2876
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 - "xmlns="http://tempuri.org/nameOfRoot.xsd" I have no idea what its pointing to & what is tempuri.org? So when this tag is in my xml tag my xpath query never works. But when I delete it work fine.
9
2148
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 should work. Also the second nav.OuterXml appears to also be wrong to me. Can someone explain to me why this does not work? (This is an example from a program we have where xpath can be entered in two parts so we have to be able
5
7925
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
2810
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 type value to be the context of an XPath expression, by converting it to an XPath object -- either boolean, string or float. I do not see how this is possible, but I would like your thoughts on it.
0
1758
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
1058
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 would recommend the O'Reilly XSLT book, it has an excellent introduction to xpath in chapter 3.
0
8483
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
8402
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
8927
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...
0
8825
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8605
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
8676
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...
0
7445
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4227
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...
2
1816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.