[xsd-users] serialize empty element

Bradley Beddoes beddoes at intient.com
Mon Jan 29 03:19:10 EST 2007


Boris Kolpackov wrote:
> Hi Bradley,
> 
> Bradley Beddoes <beddoes at intient.com> writes:
> 
>> I was wondering if there might be any suggestions as to how to serialize
>>  to an empty element.
>>
>> I have attempted to enable default ctors and serialize an object and
>> this seg faults for obvious reasons.
>>
>> Essentially I would like to be able to create an object representing an
>> element and have it written to the DOMDocument as an empty element so
>> that other code can come along and replace this empty element with on
>> the fly generated content.
> 
> I am not quite sure what you mean here by the empty element. If the
> schema allows for this element to be empty (e.g., no required
> attributes and all elements are minOccurs=0, etc.) then you should
> be able to serialize it without problems.
> 
> But I guess (from the segfault you've mentioned) that what you are
> trying to do is serialize an element without some required attributes
> or elements so that you can get the nested elements/attributes
> created (though without any legal values). This is not going to work
> since the generated serialization code expects the tree to be valid
> and to contain all required attributes and elements. I guess you will
> have to create those DOM nodes manually.

Thats exactly right in this case to replace an empty XML DSig 
<Signature/> element with the correct calculated one, essentially the 
user would present an invalid Document structure which is the corrected, 
the empty <Signature/> being used to indicate what they wish to have 
signed (as there may be multiple places a Signature could live but you 
dont want to sign in them all).

I will play some more with the dom node stuff see what I can do. I just 
figured you may have had some hidden way to mark an element as empty and 
thus just create an element with the associated name and namespace only 
at serialization time.

Bradley

> 
> hth,
> -boris


-- 
Bradley Beddoes
Lead Software Architect

Intient - "Open Source, Open Standards"




More information about the xsd-users mailing list