Here's the rationale behind this, long post:
Let's for one moment consider the case when "foo" is an element, as such
<xs:element name="foo" nillable="true" minOccurs="0" type="xs:string"/>
The value of the "foo" element can be in one of these four states:
1. non-nul, non-empty set value - setFoo("abc") with output
<foo>abc</foo>
nothing special here
2. empty set value - setFoo("") with output
<foo></foo>
you would expect that
3. null set value - setFoo(null) with output
<foo xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
this is the representation for a null value in XMLSchema.
4. value not set - unsetFoo() with output
[nothing]
representation for a value that is "not set". XMLSchema, as databases, makes
a distiction between values "not present" and values "present, but set to null"
that Java doesn't make (in addition to the distinction between "null" and
"empty").
For this reason, the semantics of set(null) in XmlBeans is "set the text of the
element to the empty string and add the "xsi:nil" attribute with the value set
to true".
Now let's consider the case of attributes. The obvious difference, from an XML
point of view is that xsi:type can no longer be used, so case #3 doesn't exist
and the algorithm in the preceding paragraph needs to be changed. So we changed
it in the minimal way, like so: "set the text of the attribute to the empty
string and done". That is the reason you see the current behaviour. Basically,
you cannot represent null values using attributes correctly.
As you noted, you can always call umset() and get the desired XML output. And
if the type of the attribute was "int" instead of "string", then you would have
no way of setting it to null and would have to call .unset() explicitly anyway.
Radu
-----Original Message-----
From: Bao Le [mailto:[EMAIL PROTECTED]
Sent: Mon 8/22/2005 7:04 PM
To: [email protected]
Cc:
Subject: Re: toString() problem
I run the code below for testing:
LOANSTATUS loanStatus = LOANSTATUS.Factory.newInstance();
System.out.println("toString: " + loanStatus.toString());//(1)
loanStatus.setLoanStatusID(null);
System.out.println("toString: " + loanStatus.toString());//(2)
loanStatus.unsetLoanStatusID();
System.out.println("toString: " + loanStatus.toString());//(3)
and the result:
<?xml version="1.0" encoding="UTF-8"?>
<xml-fragment ></xml-fragment>
<?xml version="1.0" encoding="UTF-8"?>
<xml-fragment LoanStatusID=""></xml-fragment>
<?xml version="1.0" encoding="UTF-8"?>
<xml-fragment ></xml-fragment>
The problem is XMLBeans regarding a null String as an empty String in
toString() methode.
Regards,
-----------------------------------------------------------------------------------
Bao Le
Lecturer
http://leducbao.blogspot.com
Faculty of Information Technology
Ton Duc Thang University of Technology
Mobile: +(84-95) 888 2585
-----------------------------------------------------------------------------------
Radu Preotiuc-Pietro wrote:
Can you post the declaration of the attribute “ MERSOrganizationIdentifier”?
As a general rule, XmlBeans doesn’t add attributes unless explicitly required
by the user, so there’s something else going on here.
Radu
-----Original Message-----
From: Bao Le [mailto:[EMAIL PROTECTED]
Sent: Monday, August 22, 2005 12:01 AM
To: [email protected]
Subject: Re: toString() problem
Bao Le wrote:
Dear XMLBeans Users.
I created an object by XMLBeans and using toString() for getting it's content.
The issue is the attribute does not set (nullable attribute) , the toString()
methode return the empty value.
Input:
<?xml version="1.0" encoding="UTF-8"?>
<NON_PERSON_ENTITY_DETAIL xmlns="http://mif.wdc.com/cdr"
<http://mif.wdc.com/cdr> xmlns:cdr="http://mif.wdc.com/cdr"
<http://mif.wdc.com/cdr> targetNamespace="http://mif.wdc.com/cdr"
<http://mif.wdc.com/cdr>
TaxIdentificationNumberIdentifier="String"
OrganizationType="0"
NonPersonEntityID="ID000078"
SuccessOrClauseTextDescription="String"
OrganizationTypeOtherDescription="String"
OrganizedUnderTheLawsOfJurisdictionName="String"
OrganizationLicensingTypeDescription="String"/>
Output:
<?xml version="1.0" encoding="UTF-8"?>
<NON_PERSON_ENTITY_DETAIL xmlns="http://mif.wdc.com/cdr"
<http://mif.wdc.com/cdr> xmlns:cdr="http://mif.wdc.com/cdr"
<http://mif.wdc.com/cdr> targetNamespace="http://mif.wdc.com/cdr"
<http://mif.wdc.com/cdr>
TaxIdentificationNumberIdentifier="String"
OrganizationType="0"
NonPersonEntityID="ID000078"
MERSOrganizationIdentifier="" <--- this value is null(in debug session), but
something like this when use toString() method
SuccessOrClauseTextDescription="String"
OrganizationTypeOtherDescription="String"
OrganizedUnderTheLawsOfJurisdictionName="String"
OrganizationLicensingTypeDescription="String"/>
anyone has experiences on this issue, please help me
Regards,
-----------------------------------------------------------------------------------
Bao Le
Lecturer
http://leducbao.blogspot.com
Faculty of Information Technology
Ton Duc Thang University of Technology
Mobile : +(84-95) 888 2585
-----------------------------------------------------------------------------------
Radu Preotiuc-Pietro wrote:
Hi Dennis,
Can you give me a more detailed scenario? You _can_ load an XmlBean and
save it back and the prefixes will be preserved.
We had support for canonicalization in our plans, but we had to drop it,
mainly because we couldn't get anyone interested enough in the problem
involved :p
Thanks,
Radu
-----Original Message-----
From: Dennis Sosnoski [mailto:[EMAIL PROTECTED]
Sent: Monday, August 15, 2005 6:47 PM
To: [email protected]
Subject: XML-Signature
From a quick look it appears that XMLBeans is incompatible with XML
Signature, since it doesn't retain all the information needed for XML
Canonicalization (namespace prefixes, in particular). Are there any
plans to change this and support XML Signature - or is the documentation
out of date and Canonicalization is already supported? Thanks,
- Dennis
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Start <http://us.rd.yahoo.com/evt=34442/*http:/www.yahoo.com/r/hs> your day
with Yahoo! - make it your home page
Start <http://us.rd.yahoo.com/evt=34442/*http://www.yahoo.com/r/hs> your day
with Yahoo! - make it your home page
_____
Start your day with Yahoo! - make it your home page
<http://us.rd.yahoo.com/evt=34442/*http://www.yahoo.com/r/hs>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]