Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] Node empty or not.

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: John Cowan <jcowan AT reutershealth.com>
  • To: "Jason C. Leach" <jleach AT ocis.net>
  • Cc: xom-interest AT lists.ibiblio.org
  • Subject: Re: [XOM-interest] Node empty or not.
  • Date: Thu, 19 Jun 2003 12:56:52 -0400

Jason C. Leach scripsit:

> I don't think that does what I expect. For example, in the XML node:
> ...
> <mustHave>
> <cn>jason</cn>
> <gidNumber/>
> </mustHave>
> ...
>
> The cn tag has some content, the gidNumber is empty. I would
> like to be able to destinguis between a child with content (cn)
> and without (gidNumber).

Just so. The childCount of the cn element should be 1, and the
childCount of the gidNumber element should be 0.

> <?xml version="1.0" encoding="ISO-8859-1"?>
> <objectClass type="posixGroup">
> <mustHave quantity="2">
> <cn>oop</cn>
> <gidNumber/>
> </mustHave>
> <mayHave quantity="3">
> <userPassword/>
> <memberUid/>
> <description/>
> </mayHave>
> </objectClass>
>
> System.out.println(doc.getRootElement().getFirstChildElement("mustHave").getChildCount());
>
> Returns 5. Where doc is the XML document. I'm not sure why I get 5 back.

Because there are five children of the mustHave element: namely,
some text consisting of whitespace, the cn element, some more text
consisting of whitespace, the gidNumber element, and still more text
consisting of whitespace.

An empty element has neither child elements nor character content,
and its childCount is always zero. A non-empty element has either
child elements or character content or both, and its childCount is
always non-zero.

> I would think I should get 2 or 3 (if for some reason it included the
> attribute);

No, attributes are not children.

> or better yet 1 which is exactly what I want.

Why would you expect 1?

--
John Cowan www.ccil.org/~cowan www.reutershealth.com
jcowan AT reutershealth.com
In might the Feanorians / that swore the unforgotten oath
brought war into Arvernien / with burning and with broken troth.
and Elwing from her fastness dim / then cast her in the waters wide,
but like a mew was swiftly borne, / uplifted o'er the roaring tide.
--the Earendillinwe




Archive powered by MHonArc 2.6.24.

Top of Page