xml-xmlbeans-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Saha, Sanjeev" <SS...@asce.org>
Subject RE: Testing for empty elements
Date Fri, 23 Jul 2004 20:18:21 GMT
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 [mailto:Kimberley.Coburn@softlab.de] 
	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 child.
	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 Element.toString().equals("<xml-fragement></xml-fragment>").
	There must be a better way. Does anyone know one?
	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/

View raw message