473,782 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

help with xpath request

Hello :-)

I am learning XPath, and I am trying to get child nodes
of a node whose names do *not* match a given string,
e.g :

<dummy>
<example>
<title>Exampl e 1</title>
<body>this is an example</body>
<picture>a reference to a picture</picture>
</example>
</dummy>

I want to get "body" and "picture" child nodes of the
"example" node. I thought that this request could do
the trick but it is not working :

/dummy/example/*[name()!="title"]

Can someone help me, please ?

Thanks in advance!!!

Nov 9 '06
14 2009
... a lot of yada yada from Pavel ...

Have a nice evening Pavel!

cheers
spiff

Nov 9 '06 #11
Philippe Poulard wrote:
the best thing to do is :
/dummy/example/*[not(self::title )]
Good suggestion!
--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Nov 9 '06 #12
Children, if you want to play S&M games you really ought to get a room
somewhere.

If you've got something worth saying, you don't need to resort to
attacking personalities. And if you're going to waste time debating
personalities, I for one don't care whether you have anything worth
saying. Killfiles are a good thing.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Nov 9 '06 #13
Use:

/*/*/*[not(self::title )]
I would recommend using the XPath Visualizer, using which many people have
learned XPath the fun way.
Cheers,
Dimitre Novatchev
"Mat|" <de*******@cara mail.comwrote in message
news:11******** *************@h 48g2000cwc.goog legroups.com...
Hello :-)

I am learning XPath, and I am trying to get child nodes
of a node whose names do *not* match a given string,
e.g :

<dummy>
<example>
<title>Exampl e 1</title>
<body>this is an example</body>
<picture>a reference to a picture</picture>
</example>
</dummy>

I want to get "body" and "picture" child nodes of the
"example" node. I thought that this request could do
the trick but it is not working :

/dummy/example/*[name()!="title"]

Can someone help me, please ?

Thanks in advance!!!

Nov 10 '06 #14

Philippe Poulard wrote:
Joe Kesselman wrote:
Mat| wrote:
I am learning XPath, and I am trying to get child
nodes of a node whose names do *not* match a given
string,
/dummy/example/*[name()!="title"]
And while name() certainly does work, I also have to
agree with his warning that this will turn around and
bite you when you start working with namespaced
documents.

the best thing to do is :
/dummy/example/*[not(self::title )]

if you would use namespaces, it would become :
/foo:dummy/foo:example/*[not(self::foo:t itle)]
Definitely the most elegant solution.

Still, this got me thinking. While Philippe's solution
looks neat and works well, I have a feeling that the fact
you need to do something like that (that is, 'choose all
children but <title>s') is a fairly strong hint that you
should consider redesigning your XML structure (if you
have control over that, of course). For original poster's
sample that would be something like:

<dummy>
<example title="Example 1">
<body>this is an example</body>
<picture>a reference to a picture</picture>
</example>
</dummy>

or:

<dummy>
<example>
<title>Exampl e 1</title>
<body>
<content>this is an example</content>
<picture>a reference to a picture</picture>
</body>
</example>
</dummy>

What I probably mean to say (yeah, I'm not sure what I'm
sayin' myself), is that in case you need a predicate in
your XPath that somehow feels unnatural*, although the
nodes you need selected seem to belong to a well-defined,
logically natural group, it might be worth it to consider
changing the XML's structure to actually group those
nodes in a parent element.

* for some values of 'unnatural'
but if you use instead name() :
/foo:dummy/foo:example/*[name()!="foo:ti tle"]
...will give you the same result *only* if the XML
source do use the same prefix, which is somewhat
hazardous...
I wonder, by the way. Aren't

<foo:element xmlns:foo="foo"/>

and

<bar:element xmlns:bar="foo"/>

supposed to be two completely interchangeable
representations of the same document fragment? If they
are, isn't name() just a bit broken in that it makes
those two distinguishable ?

--
Pavel Lepin

Nov 10 '06 #15

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

Similar topics

0
1929
by: gael.pegliasco | last post by:
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
0
1482
by: Thor W Hammer | last post by:
Is it possible to use dynamic xpath expressions with the <%#XPath("..")%> syntax and XmlDataSource? This is a couple of examples to illustrate what I think about: 1: <%#XPath("*")%> 2: <%#XPath("*%>]")%>
2
1669
by: xerj | last post by:
I've worked out how to retrieve a parameter from a query string in a url using Request.Querystring("whatever"). However, what I can't figure out is how to feed this into an Xpath expression. For instance, say I have an Xpath as follows: food/fruit. How do I programmatically alter the 'typeoffruit' attribute using the querystring in the url (example whatever.aspx?fruit=banana via Request.Querystring or whatever command is needed to...
4
1370
by: Mark Cooney | last post by:
OK this might be long winded by want to show you everything I am doing. Down below is the result I get from an API Call to a website called Betfair. The following is some code I am trying, but I have also tried many different variations. Dim response As HttpWebResponse = request.GetResponse() 'Get the response stream Dim reader As StreamReader = New StreamReader(response.GetResponseStream)
1
2342
by: newToAjax | last post by:
I have created an ajax application which retrievs an xml file and fills in the tab fields on the form.The code works fine in IE while its does not in Mozilla. Can you please let me know if i have to install some plugins to use XPATH? <html> <head> <title>SilverLine </title> <link rel="stylesheet" href="example.css" TYPE="text/css" MEDIA="screen"> <script type="text/javascript"> /* Optional: Temporarily hide the "tabber" class so it...
2
1774
by: Amar | last post by:
I have XML Data: <REQUEST> <PARAMETERS> <PPM Name="CCCS Filed Date" value="xxxx"></PPM> </PARAMETERS> <RECORD _FiledDate="12/15/2003"></RECORD> </REQUEST>
0
1254
by: bruce | last post by:
valid point...!! here's the test python.. ugly as it is!! Lodge It New All About ? Paste #83093
1
2218
by: bruce | last post by:
Hi. Got a test web page, that basically has two "<html" tags in it. Examining the page via Firefox/Dom Inspector, I can create a test xpath query "/html/body/form" which gets the target form for the test. The issue comes when I examine the page's source html. It looks like: <html> <body> </body>
0
10311
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
10146
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...
0
9942
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
8967
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
6733
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
5378
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
5509
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4043
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2874
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.