You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xmlbeans.apache.org by "McMillan, DouglasC" <Do...@cbsa-asfc.gc.ca> on 2006/09/01 21:12:43 UTC

RE: [jira] Commented: (XMLBEANS-220) XmlObject.xmlText(XmlOptions) outputs xsi:nil="true" where schema definition is minOccurs="0" and default value for nillable="false"

The diff is as follows ... It's not a particularly elegant solution and is most likely not up to the groups standards, but it does work. 	I also added a try/catch to stop exceptions being thrown from un-setting values that are not set. This part especially can be improved upon. Having this sort of functionality built in, perhaps off by default, but controlled by the xsdconfig would be a huge plus for me, and other groups. JAXB, Castor, etc all have this as basic functionality, but these tools all have other limitations. 


--- SchemaTypeCodePrinter.java	9 Mar 2006 15:01:31 -0000	1.2
+++ SchemaTypeCodePrinter.java	1 Sep 2006 19:05:49 -0000
@@ -2177,15 +2177,6 @@
             emitPre(sType, PrePostExtension.OPERATION_SET, identifier, isAttr, several ? "0" : "-1");
             emitGetTarget(setIdentifier, identifier, isAttr, "0", ADD_NEW_VALUE, jtargetType);
             emit(jSet + "(" + safeVarName + ");");
-
-			// Unset the value if a null was passed, the field is optional, and is not nillable.
-			if(!nillable&&optional&&!(javaType>=SchemaProperty.JAVA_FIRST_PRIMITIVE&&javaType<=SchemaProperty.JAVA_LAST_PRIMITIVE)){
-				emit("if("+safeVarName+"==null){");
-				emit("\tunset"+propertyName+"();");
-				emit("}");
-			}
-			
             emitPost(sType, PrePostExtension.OPERATION_SET, identifier, isAttr, several ? "0" : "-1");
             emitImplementationPostamble();
             endBlock();
@@ -2244,19 +2235,10 @@
             startBlock();
             emitImplementationPreamble();
             emitPre(sType, PrePostExtension.OPERATION_REMOVE, identifier, isAttr, several ? "0" : "-1");
-
-			// Added a try/catch
-			emit("try{");
-			
             if (isAttr)
                 emit("get_store().remove_attribute(" + identifier + ");");
             else
                 emit("get_store().remove_element(" + setIdentifier + ", 0);");
-			
-			emit("}catch(Exception ignoreException){}");
-			
-			
             emitPost(sType, PrePostExtension.OPERATION_REMOVE, identifier, isAttr, several ? "0" : "-1");
             emitImplementationPostamble();
             endBlock();

-----Original Message-----
From: Radu Preotiuc-Pietro [mailto:radup@bea.com]
Sent: August 31, 2006 12:57 PM
To: dev@xmlbeans.apache.org
Subject: RE: [jira] Commented: (XMLBEANS-220)
XmlObject.xmlText(XmlOptions) outputs xsi:nil="true" where schema
definition is minOccurs="0" and default value for nillable="false"


Could you attach a diff with your change to the JIRA to see what
approach did you take?

Thanks,
Radu 

-----Original Message-----
From: McMillan, DouglasC [mailto:DouglasC.McMillan@cbsa-asfc.gc.ca] 
Sent: Thursday, August 31, 2006 4:28 AM
To: dev@xmlbeans.apache.org
Subject: RE: [jira] Commented: (XMLBEANS-220)
XmlObject.xmlText(XmlOptions) outputs xsi:nil="true" where schema
definition is minOccurs="0" and default value for nillable="false"

I have a few simple modifications available if the null/nil changes are
of interest to you. Basically, setting a null value removes an optional
element. I think this has been discussed several times before, but I'm
still interested in having this implemented in the code generator as an
option if possible. 



-----Original Message-----
From: Adam Lewandowski (JIRA) [mailto:xmlbeans-dev@xml.apache.org]
Sent: August 30, 2006 15:43 PM
To: xmlbeans-dev@xml.apache.org
Subject: [jira] Commented: (XMLBEANS-220) XmlObject.xmlText(XmlOptions)
outputs xsi:nil="true" where schema definition is minOccurs="0" and
default value for nillable="false"


    [
http://issues.apache.org/jira/browse/XMLBEANS-220?page=comments#action_1
2431668 ] 
            
Adam Lewandowski commented on XMLBEANS-220:
-------------------------------------------

You are correct, if the element is not explicitly set to null, then the
element is not generated at all (when maxOccurs=0). This works (at least
in 2.2.0), thanks! 
I was unaware that XmlBeans does not guarantee schema compliance. It's
not the end of the world, but I was expecting that since I fed it the
schema to begin with it would stick to it when generating output.

> XmlObject.xmlText(XmlOptions) outputs xsi:nil="true" where schema
definition is minOccurs="0" and default value for nillable="false"
> ----------------------------------------------------------------------
> --------------------------------------------------------------
>
>                 Key: XMLBEANS-220
>                 URL: http://issues.apache.org/jira/browse/XMLBEANS-220
>             Project: XMLBeans
>          Issue Type: Bug
>          Components: XmlObject
>    Affects Versions: Version 2
>         Environment: Windows XP, JDK 1.4.2_05
>            Reporter: James Webster
>
> We have defined a type in the schema as...
> <xsd:complexType name="MyType">
>    <xsd:element name="mandatoryElement" type="xsd:string"/>
>    <xsd:element name="optionalElement" minOccurs="0" 
> type="xsd:string"/> </xsd:complexType> According to the XML Schema 
> specification, false is the default value for the optional 'nillable'
attribute on xsd:element. So the 'optionalElement' element is
nillable='false'.
> We instantiate an instance of the MyType class, set the mandatory
element and get the value of xmlText()...
> MyType type = MyType.Factory.newInstance(); 
> type.setMandatoryElement("someValue");
> String xmlText = type.xmlText();
> The value of xmlText generated by XMLBeans v2.0 is...
> <MyType>
>   <mandatoryElement>someValue</mandatoryElement>
>   <optionalElement xsi:nil="true"/>
> </MyType>
> BUT, we would expect (given that optionalElement is NOT nillable) to
see the following...
> <MyType>
>   <mandatoryElement>someValue</mandatoryElement>
> </MyType>
> Our investigations into the XMLBeans API suggests that it is not
possible (via XmlOptions, etc) to suppress the xsi: attributes, so we
believe this may be a bug? We are at no point explicitly setting the
optionalElement to null.

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org

_______________________________________________________________________
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.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org