Details
-
Type:
Bug
-
Status:
Open
-
Priority:
Critical
-
Resolution: Unresolved
-
Affects Version/s: 0.9.6, 0.9.7
-
Fix Version/s: None
-
Component/s: XML
-
Labels:None
-
Environment:Windows XP Pro
-
Number of attachments :
Description
Input schema:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
targetNamespace="http://schemas.data.net/fields"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:dsf="http://schemas.data.net/fields"
xmlns="http://schemas.data.net/fields"
elementFormDefault="qualified">
<xs:simpleType name="STRING30_Type">
<xs:restriction base="xs:string">
<xs:maxLength value="30"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="STRING100_Type">
<xs:restriction base="xs:string">
<xs:maxLength value="100"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="DEPARTMENTCODE" type="STRING30_Type"/>
<xs:element name="DESCRIPTION" type="STRING100_Type"/>
<xs:complexType name="DEPARTMENTID_Type">
<xs:sequence>
<xs:element ref="DEPARTMENTCODE"/>
<xs:element ref="DESCRIPTION" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:element name="DEPARTMENTID" type="DEPARTMENTID_Type"/>
<xs:element name="TESTCODE" type="STRING30_Type" default="*"/>
<xs:complexType name="TESTRATEID_Type">
<xs:sequence>
<xs:element ref="DEPARTMENTID"/>
<xs:element ref="TESTCODE" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:element name="testEl" type="TESTRATEID_Type" />
</xs:schema>
is run through the following test code:
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import org.exolab.castor.xml.schema.Schema;
import org.exolab.castor.xml.schema.reader.SchemaReader;
import org.exolab.castor.xml.schema.writer.SchemaWriter;
public class SchemaBugTest
{
public static void main(String[] aArgs) throws Exception
{ String xsdFileName = aArgs[0]; SchemaBugTest test = new SchemaBugTest(xsdFileName); test.runTest(); }private String mXsdFileName;
public SchemaBugTest( String aXsdFileName )
{ mXsdFileName = aXsdFileName; }public void runTest() throws Exception
{ Schema schema = loadSchemaFromFile(); writeSchema( schema ); } protected Schema loadSchemaFromFile() throws Exception
{
File file = new File(mXsdFileName);
if( !file.isFile() )
SchemaReader reader = new SchemaReader( file.toURL().toExternalForm() );
Schema schema = reader.read();
schema.validate();
return schema;
}
protected void writeSchema( Schema aSchema ) throws Exception
{
OutputStreamWriter out = null;
try
finally
{
try
catch(IOException io)
{/* eat me*/} }
}
}
and results in the following output (indented and comment added manually):
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dsf="http://schemas.data.net/fields"
xmlns="http://schemas.data.net/fields"
targetNamespace="http://schemas.data.net/fields"
elementFormDefault="qualified">
<xs:element name="TESTCODE" type="dsf:STRING30_Type" default="*"/>
<xs:element name="DESCRIPTION" type="dsf:STRING100_Type"/>
<xs:element name="DEPARTMENTCODE" type="dsf:STRING30_Type"/>
<xs:element name="testEl" type="dsf:TESTRATEID_Type"/>
<xs:element name="DEPARTMENTID" type="dsf:DEPARTMENTID_Type"/>
<xs:complexType name="DEPARTMENTID_Type">
<xs:sequence>
<xs:element ref="dsf:DEPARTMENTCODE"/>
<xs:element ref="dsf:DESCRIPTION" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="TESTRATEID_Type">
<xs:sequence>
<xs:element ref="dsf:DEPARTMENTID"/>
<!-- ************************** -->
<!-- THIS IS THE PROBLEM -->
<!-- ************************** -->
<xs:element ref="dsf:TESTCODE" minOccurs="0" default="*"/>
</xs:sequence>
</xs:complexType>
<xs:simpleType name="STRING30_Type">
<xs:restriction base="xs:string">
<xs:maxLength value="30"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="STRING100_Type">
<xs:restriction base="xs:string">
<xs:maxLength value="100"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
Note that the default="*" attribute has been inserted (on deserialization). Validation against this schema fails in xerces, xml spy, etc.
Sample xml:
<?xml version="1.0" encoding="UTF-8"?>
<tns:testEl
xmlns="http://schemas.data.net/fields"
xmlns:tns="http://schemas.data.net/fields" >
<tns:DEPARTMENTID>
<tns:DEPARTMENTCODE>DeptCode</tns:DEPARTMENTCODE>
<tns:DESCRIPTION>Dummy Desc</tns:DESCRIPTION>
</tns:DEPARTMENTID>
<tns:TESTCODE>mytestcode</tns:TESTCODE>
</tns:testEl>
Same issue encountered here. In addition, the "default" attribute can contain any value. The attribute will be "copied to" the referring element.
Source XSD:
Program Source Code:
Program Output (Manually Formatted and Indented):
Will this bug be fixed in the next stable release / milestone build? Thanks.