xml-xmlbeans-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eric Vasilik" <eric...@bea.com>
Subject RE: Testing for empty elements
Date Mon, 26 Jul 2004 16:48:32 GMT
The getTextValue method will return any text in the content of the
element, but if there are any empty elements there, getTextValuye will
still return "".  In addition to making sure getTextValue returns "",
you should also call toFirstChild and make sure it returns false to make
sure there are no child elements.  Also, if your definition of empty
includes attributes, you will want to check for that, and comments and
PI's may still be in there as well, you may want to check for that if
your requirements deem so.
- Eric
-----Original Message-----
From: Coburn Kimberley [mailto:Kimberley.Coburn@softlab.de] 
Sent: Friday, July 23, 2004 1:28 PM
To: 'xmlbeans-user@xml.apache.org'
Subject: RE: Testing for empty elements
Hello Sanjeev,
Thank you for the suggestion. I will try it.
Best regards,
	-----Original Message-----
	From: Saha, Sanjeev [mailto:SSaha@asce.org]
	Sent: Freitag, 23. Juli 2004 22:18
	To: xmlbeans-user@xml.apache.org
	Subject: RE: Testing for empty elements
	XmlCursor cursor = customer.newCursor(); // assuming customer is
already an XmlObject
	cursor.selectPath("Vehicle"); // or "./Vehicle" or
"child::Vehicle" which ever is comfortable
	if (cursor.toNextSelection())
	    String vehicleValue = cursor.getTextValue();
	    // value returned will be an emptyString [ "" ] if blank
	Hope this helps,
		-----Original Message----- 
		From: Coburn Kimberley
		Sent: Fri 7/23/2004 2:11 PM 
		To: xmlbeans-user@xml.apache.org 
		Subject: Testing for empty elements
		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
		For an instance:
		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
		There must be a better way. Does anyone know one?
		Kimberley Coburn
		To unsubscribe, e-mail:
		For additional commands, e-mail:
		Apache XMLBeans Project -- URL:

View raw message