Hi Artem

 

Hmmm. I think I there are sufficient reasons to do it the way we do it.

 

Consider if we were to do it such that the attribute got “automatically added”. Then for people who pass in an instance doc with a defaulted attribute (i.e. it is missing but has a default value) if they output their document it now looks different from what went in. The meaning is the same but the actual text is different. If they wanted to go back to the original state they’d somehow have to distinguish which elements were originally missing and explicitly unset them. Identifying which attributes were originally missing as opposed to attributes which were not missing but happened to have their default values would be difficult. And round-tripping in this fashion can be important to some people.

 

Another way of looking at it is that the purpose of having a default attribute in the schema is so that instance documents with those attributes missing would be interpreted correctly – this should be true of whatever is interpreting the instance doc – so it is correct for XmlBeans to produce documents that look that way – especially since you can then specifically override if you want to.

 

Anyway – that’s my 2c FWIW.

 

Cheers,

 

Lawrence

 


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Friday, March 03, 2006 2:10 PM
To: [email protected]
Subject: RE: Default attribute value and serialization

 

Hi Lawrence,

 

I see.  That’s a bit of a let down.  For me the whole purpose of having a default value in the schema was so that I didn’t have to explicitly set it via the setMethod() call.  But if that is not possible I’ll have to work around it.  Thanks any way.

 

Regards,

 

Artem

 


From: Lawrence Jones [mailto:[EMAIL PROTECTED]
Sent: Friday, March 03, 2006 5:03 PM
To: [email protected]
Subject: RE: Default attribute value and serialization

 

Hi Artem

 

Ah – so it’s not that the attribute has a empty value (i.e. <def:Section … method=”” >) - rather that the attribute is missing altogether. In that case I think what you are seeing is the expected behavior. If you fail to set an attribute but that attribute has a default value then for infoset validation purposes that attribute is present (see http://www.w3.org/TR/xmlschema-1/#sic-attrDefault) and hence if you call getMethod() you will get back the default value even though the attribute is not present.

 

If you explicitly want it to be present you can simply call setMethod() – after that the attribute (and its value) will show up in the output XML. If you simply want to check whether it is actually present or not you can use the isSetMethod() method.

 

Cheers,

 

Lawrence

 


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Friday, March 03, 2006 10:33 AM
To: [email protected]
Subject: RE: Default attribute value and serialization

 

Here’s a shortened version of the code.  I left out everything that didn’t have to do with the attribute in question.

 

    ConsolePageDocument doc = ConsolePageDocument.Factory.newInstance();

    ConsolePage consolePage = doc.addNewConsolePage();

    Right right = consolePage.addNewRight();

    SectionType section = right.addNewSection();

    section.setName("S/MIME Provider Settings");

    section.setHelp("Settings to enable the use of Secure Multipurpose Internet Mail Extensions");

    section.setStyle(SectionType.Style.FIELDSET);

    section.setForm("setSMIME");

    HTTPMethod.Enum m = section.getMethod(); // getting back HTTPMethod.POST

 

    // serialize document

    ByteArrayOutputStream result = new ByteArrayOutputStream();

    doc.save(result);

 

Here is what the Section node looks like when serialized…

 

<def:Section name="S/MIME Provider Settings" help="Settings to enable the use of Secure Multipurpose Internet Mail Extensions" style="fieldset" form="setSMIME">

 

Thanks,

 

Artem

 


From: Lawrence Jones [mailto:[EMAIL PROTECTED]
Sent: Friday, March 03, 2006 12:57 PM
To: [email protected]
Subject: RE: Default attribute value and serialization

 

Hi Artem

 

Can you send the code you are using to create your document please?

 

Cheers,

 

Lawrence

 


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Friday, March 03, 2006 9:14 AM
To: [email protected]
Subject: Default attribute value and serialization

 

Hi,

 

There appears to be a problem in XMLBeans with handling of default values for attributes.  I have an attribute in my schema that has a type of enumeration and also has a default value

 

             <xs:attribute name="method" type="com:HTTPMethod" default="POST"/>

 

       <xs:simpleType name="HTTPMethod">

             <xs:restriction base="xs:string">

                    <xs:enumeration value="GET"/>

                    <xs:enumeration value="POST"/>

             </xs:restriction>

       </xs:simpleType>

 

When I create my document using XMLBeans and serialize it via save(OutputStream), I end up with the method attribute having an empty value.  However, if I make a call to getMethod(), I’m getting the expected default value.  What am I doing wrong?

 

Thank you,

 

Artem

_______________________________________________________________________
Notice:  This email message, together with any attachments, may contain
information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
entities,  that may be confidential,  proprietary,  copyrighted  and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.
_______________________________________________________________________
Notice:  This email message, together with any attachments, may contain
information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
entities,  that may be confidential,  proprietary,  copyrighted  and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.
_______________________________________________________________________
Notice:  This email message, together with any attachments, may contain
information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
entities,  that may be confidential,  proprietary,  copyrighted  and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.

Reply via email to