473,396 Members | 1,760 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,396 software developers and data experts.

easy question - empty element?

In the following XML:

<?xml version="1.0" encoding="utf-8" ?>
<Plcy service="ILiability" boId ="LifePolicy, 1">
<Prem service="IPremium" boId ="RegularPremium, 1"></Prem>
<L1 service="ILifeMain" type = "Life1">
<FirstName>Sheila</FirstName>
<Age>65</Age>
<Relation>spouse</Relation>
</L1>
<L2 service="ILife" type = "Life2">
<FirstName>Bruce</FirstName>
<Age>70</Age>
</L2>
</Plcy>

I would like to select Nodes with boId attribute which are empty. I am
using an XPath expression:

"//*[@boId and not(text())]"

but MS VS XPathNavigator's Select() returns both Plcy and Prem. It
also sets IsEmpty field of Prem node to false.

Whose fault is it - mine or MS?

Yours,

Valery the Newbie

Oct 30 '07 #1
5 3753
"Valery" <va*****@gmail.comwrote in message
news:11**********************@k79g2000hse.googlegr oups.com...
In the following XML:

<?xml version="1.0" encoding="utf-8" ?>
<Plcy service="ILiability" boId ="LifePolicy, 1">
<Prem service="IPremium" boId ="RegularPremium, 1"></Prem>
<L1 service="ILifeMain" type = "Life1">
<FirstName>Sheila</FirstName>
<Age>65</Age>
<Relation>spouse</Relation>
</L1>
<L2 service="ILife" type = "Life2">
<FirstName>Bruce</FirstName>
<Age>70</Age>
</L2>
</Plcy>

I would like to select Nodes with boId attribute which are empty. I am
using an XPath expression:

"//*[@boId and not(text())]"

but MS VS XPathNavigator's Select() returns both Plcy and Prem. It
also sets IsEmpty field of Prem node to false.

Whose fault is it - mine or MS?

Yours,

Valery the Newbie
Maybe a whitespace issue. Try:
//*[@boId and not(normalize-space())]

--

Joe Fawcett (MVP - XML)

http://joe.fawcett.name
Oct 30 '07 #2
Valery wrote:
In the following XML:

<?xml version="1.0" encoding="utf-8" ?>
<Plcy service="ILiability" boId ="LifePolicy, 1">
<Prem service="IPremium" boId ="RegularPremium, 1"></Prem>
<L1 service="ILifeMain" type = "Life1">
<FirstName>Sheila</FirstName>
<Age>65</Age>
<Relation>spouse</Relation>
</L1>
<L2 service="ILife" type = "Life2">
<FirstName>Bruce</FirstName>
<Age>70</Age>
</L2>
</Plcy>

I would like to select Nodes with boId attribute which are empty. I am
using an XPath expression:

"//*[@boId and not(text())]"
IN English that means "all elements having attribute bold and not having
at least one child text node". Plcy and Prem both satisfy this condition.
Try wider - select nodes that have no child nodes of any type at all:

"//*[@boId and not(node())]"

--
Oleg Tkachenko [XML MVP, MCPD]
http://www.tkachenko.com/blog | http://www.XmlLab.Net
Oct 30 '07 #3
"Oleg Tkachenko [MVP]" <so**@body.comwrote in message
news:ea**************@TK2MSFTNGP04.phx.gbl...
Valery wrote:
>In the following XML:

<?xml version="1.0" encoding="utf-8" ?>
<Plcy service="ILiability" boId ="LifePolicy, 1">
<Prem service="IPremium" boId ="RegularPremium, 1"></Prem>
<L1 service="ILifeMain" type = "Life1">
<FirstName>Sheila</FirstName>
<Age>65</Age>
<Relation>spouse</Relation>
</L1>
<L2 service="ILife" type = "Life2">
<FirstName>Bruce</FirstName>
<Age>70</Age>
</L2>
</Plcy>

I would like to select Nodes with boId attribute which are empty. I am
using an XPath expression:

"//*[@boId and not(text())]"

IN English that means "all elements having attribute bold and not having
at least one child text node". Plcy and Prem both satisfy this condition.
Try wider - select nodes that have no child nodes of any type at all:

"//*[@boId and not(node())]"

--
Oleg Tkachenko [XML MVP, MCPD]
http://www.tkachenko.com/blog | http://www.XmlLab.Net
Prem appears to have no content.

--

Joe Fawcett (MVP - XML)

http://joe.fawcett.name
Oct 30 '07 #4
Joe Fawcett wrote:
"Oleg Tkachenko [MVP]" <so**@body.comwrote in message
news:ea**************@TK2MSFTNGP04.phx.gbl...
>Valery wrote:
>>In the following XML:

<?xml version="1.0" encoding="utf-8" ?>
<Plcy service="ILiability" boId ="LifePolicy, 1">
<Prem service="IPremium" boId ="RegularPremium, 1"></Prem>
<L1 service="ILifeMain" type = "Life1">
<FirstName>Sheila</FirstName>
<Age>65</Age>
<Relation>spouse</Relation>
</L1>
<L2 service="ILife" type = "Life2">
<FirstName>Bruce</FirstName>
<Age>70</Age>
</L2>
</Plcy>

I would like to select Nodes with boId attribute which are empty. I am
using an XPath expression:

"//*[@boId and not(text())]"
IN English that means "all elements having attribute bold and not having
at least one child text node". Plcy and Prem both satisfy this condition.
Try wider - select nodes that have no child nodes of any type at all:

"//*[@boId and not(node())]"

--
Oleg Tkachenko [XML MVP, MCPD]
http://www.tkachenko.com/blog | http://www.XmlLab.Net

Prem appears to have no content.
Yes, but it has end tag, so in XmlReader/XPathNavigator terms isn't
empty element:

XPathNavigator.IsEmptyElement Property

When overridden in a derived class, gets a value indicating whether the
current node is an empty element without an end element tag.

http://msdn2.microsoft.com/en-us/lib...tyelement.aspx

--
oleg
Oct 30 '07 #5
On Oct 31, 6:49 am, Oleg Tkachenko <f...@dummy.comwrote:
Joe Fawcett wrote:
"Oleg Tkachenko [MVP]" <s...@body.comwrote in message
news:ea**************@TK2MSFTNGP04.phx.gbl...
Valery wrote:
In the following XML:
><?xml version="1.0" encoding="utf-8" ?>
<Plcy service="ILiability" boId ="LifePolicy, 1">
<Prem service="IPremium" boId ="RegularPremium, 1"></Prem>
<L1 service="ILifeMain" type = "Life1">
<FirstName>Sheila</FirstName>
<Age>65</Age>
<Relation>spouse</Relation>
</L1>
<L2 service="ILife" type = "Life2">
<FirstName>Bruce</FirstName>
<Age>70</Age>
</L2>
</Plcy>
>I would like to select Nodes with boId attribute which are empty. I am
using an XPath expression:
> "//*[@boId and not(text())]"
IN English that means "all elements having attribute bold and not having
at least one child text node". Plcy and Prem both satisfy this condition.
Try wider - select nodes that have no child nodes of any type at all:
"//*[@boId and not(node())]"
--
Oleg Tkachenko [XML MVP, MCPD]
http://www.tkachenko.com/blog|http://www.XmlLab.Net
Prem appears to have no content.

Yes, but it has end tag, so in XmlReader/XPathNavigator terms isn't
empty element:

XPathNavigator.IsEmptyElement Property

When overridden in a derived class, gets a value indicating whether the
current node is an empty element without an end element tag.

http://msdn2.microsoft.com/en-us/lib...th.xpathnaviga...

--
oleg- Hide quoted text -

- Show quoted text -
Wow (surprised) and thanks. It works indeed.
V.

Oct 30 '07 #6

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

Similar topics

4
by: Derek Basch | last post by:
Hello All, I ran into a problem while dynamically constructing XHTML documents using minidom. If you create a script tag such as: script_node_0 = self.doc.createElement("script")...
13
by: Mikko Ohtamaa | last post by:
From XML specification: The representation of an empty element is either a start-tag immediately followed by an end-tag, or an empty-element tag. (This means that <foo></foo> is equal to...
13
by: vega | last post by:
How do I detect empty tags if I have the DOM document? For example: <br /> and <br></br> I tried org.w3c.dom.Node.getFirstChild(), it returns null for both <br /> and <br></br> I also tried...
18
by: Neal | last post by:
According to the specs (http://www.w3.org/TR/html401/struct/links.html#h-12.2), the <a> element requires an end tag. And so, when we use <A NAME="foo"> in HTML 2.0 to 4.01, it won't validate,...
3
by: Lukas | last post by:
title: xml to xml mapping: empty elements output although input element is not empty Why is is that when mapping from a XML schema to another XML schema, when drawing a default connection...
2
by: Andreas Palm | last post by:
I have a dataset that has DBNull in certain columns, now when I write out this one to XML, I only get the columns as elements that do have data in it. However I do need also the empty colums as...
1
by: tMan | last post by:
whats the xpath to get all the empty nodes in a document. in the xml below i want to get the nodes <empty> and <t> all other nodes either have a child node or text in them <root> <test> <se>...
5
by: wolf_y | last post by:
My question is simply: under what conditions will empty tags of the form <MOM></MOM> pass schema validation? Of course, the mirror question is: under what conditions will empty tags fail...
7
by: kumar.senthil | last post by:
Hi, I'm using XmlSerializer to create an object from the XML string. I would like to know whether I can get a null value for an empty XML element. Actually the XmlSerializer assigns "" (empty...
3
by: Valery | last post by:
In the following XML: <?xml version="1.0" encoding="utf-8" ?> <Plcy service="ILiability" boId ="LifePolicy, 1"> <Prem service="IPremium" boId ="RegularPremium, 1"></Prem> <L1...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...
0
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
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
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,...

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.