all groups > dotnet xml > october 2007 >
You're in the

dotnet xml

group:

easy question - empty element?



Re: easy question - empty element? Joe Fawcett
10/30/2007 12:00:00 AM
dotnet xml: [quoted text, click to view]
Maybe a whitespace issue. Try:
//*[@boId and not(normalize-space())]

--

Joe Fawcett (MVP - XML)

http://joe.fawcett.name

Re: easy question - empty element? Oleg Tkachenko [MVP]
10/30/2007 12:00:00 AM
[quoted text, click to view]

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]
easy question - empty element? Valery
10/30/2007 12:31:29 AM
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
Re: easy question - empty element? Joe Fawcett
10/30/2007 4:18:56 PM
[quoted text, click to view]

Prem appears to have no content.

--

Joe Fawcett (MVP - XML)

http://joe.fawcett.name

Re: easy question - empty element? Valery
10/30/2007 4:31:02 PM
[quoted text, click to view]

Wow (surprised) and thanks. It works indeed.
V.
Re: easy question - empty element? Oleg Tkachenko
10/30/2007 9:49:31 PM
[quoted text, click to view]

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/library/system.xml.xpath.xpathnavigator.isemptyelement.aspx

--
AddThis Social Bookmark Button