469,640 Members | 1,561 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,640 developers. It's quick & easy.

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 3540
"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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Derek Basch | last post: by
13 posts views Thread by vega | last post: by
18 posts views Thread by Neal | last post: by
7 posts views Thread by kumar.senthil | last post: by
3 posts views Thread by Valery | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.