xml-xmlbeans-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eric Vasilik" <eric...@bea.com>
Subject RE: Fixed Attribute
Date Fri, 26 Mar 2004 19:09:21 GMT
Values for fixed attributes are automatically returned from the getters, even though they do
not exist in the live document -- they are supplying default values.  However, validation
requires that they actually be there (the required attribute in your schema).  One way to
deal with this is to stop returning them as default attribute values.  Or, perhaps we could
automatically add fixed attributes to new elements.  Not sure either of these is a good thing
to do.

Hope this make more sense of the issue,
Eric

-----Original Message-----
From: Murphy, Eric [mailto:erimurph@pfc.cfs.nrcan.gc.ca] 
Sent: Friday, March 26, 2004 8:45 AM
To: 'xmlbeans-user@xml.apache.org'
Subject: Fixed Attribute 


XmlBeans -

I have a simple test schema which I have attached which declares some fixed attributes.  Values
for these attributes can be retrieved using the corresponding getters from the document I
create using XmlBeans.  However validation of the document fails with messages saying there
is nothing there for these required attributes.

I find this behaviour incorrect.  Am I missing something?

Sample code:

    TopElementDocument doc = TopElementDocument.Factory.newInstance();
    TopElement top         = doc.addNewTopElement();
    SecondLevel second     = top.addNewSecondLevel();
    ThirdLevel third       = second.addNewThirdLevel();
    
    // print out the required fixed top_att, second_att, third_attr
    System.out.println("Value of topAttr = " + top.getTopAttr());    
    System.out.println("Value of secondAttr = " + second.getSecondAttr());
    System.out.println("Value of thirdAttr = " + third.getThirdAttr());
    
    ArrayList errorsList = new ArrayList();
    XmlOptions options = new XmlOptions().setErrorListener(errorsList);
    doc.validate(options);
    
    // Suprisingly errors here indicate the above attributes are missing
    System.out.println(errorsList.toString());

    // print out the document and see there is nothing there for the attributes
    options.setSavePrettyPrint();
    doc.save(System.out, options);

Output from above code:

Value of topAttr = top attribute
Value of secondAttr = second attribute
Value of thirdAttr = third attribute

[error: Expected attribute:  top_attr in element top_element@http://nfis.org/nfi, 
 error: Expected attribute:  second_attr in element second_level, 
 error: Expected attribute:  third_attr in element third_level]

<?xml version="1.0" encoding="UTF-8"?>
<nfi:top_element xmlns:nfi="http://nfis.org/nfi">
  <second_level>
    <third_level/>
  </second_level>
</nfi:top_element>

Eric Murphy
Software Developer (NFIS)

erimurph@pfc.forestry.ca
tel/tél: 250-363-6038
fax / télécopieur 250-363-6004

Natural Resources Canada
Pacific Forestry Centre
506 West Burnside Road
Victoria BC V8Z 1M5

Ressources naturelles Canada
Centre de foresterie du Pacifique
506 rue Burnside ouest
Victoria, Colombie-Britanique V8Z 1M5

- ---------------------------------------------------------------------
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/


Mime
View raw message