You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xmlbeans-user@xml.apache.org by Coburn Kimberley <Ki...@softlab.de> on 2004/07/23 20:11:25 UTC

Testing for empty elements

Hello,

I am looking for a good way to test whether an element is empty. For example, I have a Customer type that has a Vehicle type as child.

For an instance:

<Customer>
  <Vehicle/>
  <OtherElement>blahblahblah</OtherElement>
</Customer>

I want to be able to either ask the Customer if its Vehicle is empty or ask the Vehicle directly if it is empty.

I thought I could do this with isNil() and isFooNil(). Anyhow, that's how I interpreted the Bea XMLBean documentation on these methods. I've found out via experimentation that this is not so - i.e. isNil()/isFooNil() only look at the xsi:nil attribute to see if it is true or false; if the attribute is missing (in my case, yes), false is always returned. (I set the nillable attribute in the schema, but this seems to only mean that I then get methods which I can use to explicitly set the xsi:nil attribute).

In any case, all I want to do is ask if the element is empty - not if an attribute has a certain value. At present, I am using the very ugly workaround of testing for Element.toString().equals("<xml-fragment/>") or Element.toString().equals("<xml-fragement></xml-fragment>").
 
There must be a better way. Does anyone know one?

Thanks,

Kimberley Coburn


- ---------------------------------------------------------------------
To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/