473,503 Members | 1,136 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Selecting nodes where a specific child does NOT exist

Hi there,

I have been given a rather poor schema for an XML file in the
following format :
<item>
<key>ProductCode</key>
<value>1234-5678</value>
<key>Description</key>
<value>Widget 1</value>
<key>Price</key>
<value>199.95</value>
</item>
<item>
<key>ProductCode</key>
<value>2345-6789</value>
<key>Description</key>
<value>Widget 2</value>
<key>Price</key>
<value>149.95</value>
</item>
<item>
<key>ProductCode</key>
<value>3456-7890</value>
<key>Description</key>
<value>Widget 3</value>
<key>Price</key>
<value>299.95</value>
<key>ignore</key>
<value>true</value>
</item>
As you can see, the format is far from ideal. What I need to be able
to do is apply formatting to only those nodes that do not contain a
subnode called "ignore". The value (true) is irrelevent since this
only ever appears if the ignore element is present.

I can select the nodes to ignore in the following way
item/key[text()='ignore']/..
but I am stumped as to how to select those nodes that do not contain
the ignore flag. obviously,
item/key[text()!='ignore']/..


would not work, because it would return a node for each element that
contains a child node that is not called "ignore", and worse, it would
return them once for each child node.

Can anyone help, please?

TIA
Marc.
Nov 18 '05 #1
2 1341


Marc Jennings wrote:

item/key[text()!='ignore']/..


You can do
item[not(key = 'ignore')]
to select item elements not having a key child with contents ignore or
if the above is what you want to change then use e.g.
item/key[not(. = 'ignore')]

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 18 '05 #2
Martin, you are a saviour! That worked beautifully.
item[not(key = 'ignore')]
Thank you.

On Fri, 18 Nov 2005 13:54:28 +0100, Martin Honnen <ma*******@yahoo.de>
wrote:


Marc Jennings wrote:

item/key[text()!='ignore']/..


You can do
item[not(key = 'ignore')]
to select item elements not having a key child with contents ignore or
if the above is what you want to change then use e.g.
item/key[not(. = 'ignore')]


Nov 18 '05 #3

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

Similar topics

1
2106
by: Gordon - Adelphia | last post by:
I have a question regarding xhtml. Why, why, why does the ELEMENT <body> allow “unblocked” text. HTML does not (though, most browsers will render). Xhtml (transitional) however allows text nodes...
9
16599
by: Tjerk Wolterink | last post by:
Hello, suppose i have a dom like this: <a> - <b> - <b> - <d> - </b> - <c>
6
3498
by: Nikhil Patel | last post by:
Hi all, Following is a portion of an XML document. I need to remove all nodes that belong to ns0 without deleting their child nodes. So in the following example , I want to delete "ns0:Proposal"...
1
1565
by: Nancy Shelley | last post by:
Hi all: I am building a navigation menu using telerik's rad treeview I am able to build the outer menu but not the children. How do I select the child nodes (item) from within the loop? Any...
2
1464
by: Saurabh Sharma | last post by:
Hi, I am using Dom Parsing in Xml. I am the parent node and it has many children and each children has many children. I want to select children with a given name . Is there any method by which we...
2
7479
by: Tymbow | last post by:
I'm building a web application that is analogous to the Windows XP file explorer in function. The left column contains a TreeView, and the right column a DataGrid populated by selecting TreeView...
1
2312
by: Daniel Rucareanu | last post by:
Hello, Does anybody knows how can you delete, in just one step, not using a loop, a subset of the child nodes of a given DOM parent node? The subset will be continous, so for example, if the...
1
1531
by: jdhcards | last post by:
Hello, I've been banging my head against a problem all day without a solution, and I'm hoping you all can help. I've got a piece of XML that defines a set of elements in a flat list. Each of...
2
3312
by: Catch_22 | last post by:
Hi, I have a stored procedure that has to extract the child records for particular parent records. The issue is that in some cases I do not want to extract all the child records only a...
0
7203
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,...
0
7089
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...
0
7282
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,...
1
6995
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...
0
7463
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...
0
5581
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,...
0
3157
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1515
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 ...
0
389
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...

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.