You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ws.apache.org by "Steven Van Loon (JIRA)" <ji...@apache.org> on 2019/08/09 12:00:00 UTC

[jira] [Created] (XMLSCHEMA-57) Unbound prefix after serialization of schema

Steven Van Loon created XMLSCHEMA-57:
----------------------------------------

             Summary: Unbound prefix after serialization of schema
                 Key: XMLSCHEMA-57
                 URL: https://issues.apache.org/jira/browse/XMLSCHEMA-57
             Project: XmlSchema
          Issue Type: Bug
    Affects Versions: 2.2.4
            Reporter: Steven Van Loon
         Attachments: UnionSerialization.java, union-schema.xsd

Hi,

I have a schema that contains a union of two types, one simple type that is defined in the schema itself and a dateTime. See attached file union-schema.xsd.

First, I read the schema into an XmlSchema
{code:java}
XmlSchema schema;
try (InputStream is = UnionSerialization.class.getResourceAsStream("union-schema.xsd")) {
 schema = new XmlSchemaCollection().read(new InputSource(is));
}{code}
 Next, I ask to serialize it to a Document and print it to standard output:
{code:java}
Document schemaDocument = schema.getSchemaDocument();
System.out.println(asText(schemaDocument));
{code}
The XML that is printed to standard out is not a valid XML schema anymore:
{code:xml}
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://some.uri" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://some.uri">
  <xs:element name="DynamicObject">
    <xs:complexType>
      <xs:sequence>
        <xs:element xmlns:q1="http://some.uri" name="DatePicker1" type="myDateTime"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:simpleType name="emptyString">
    <xs:restriction base="xs:string">
      <xs:length value="0"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="myDateTime">
    <xs:union memberTypes="q2:emptyString xs:dateTime"/>
  </xs:simpleType>
</xs:schema>{code}
the memberTypes of the union of simpleType myDateTime contains a prefix q2 which is not defined anymore in the document.

This is also the exact error I get when feeding the document to another XmlSchemaCollection:
{code:java}
new XmlSchemaCollection().read(schemaDocument, null);
{code}
{noformat}
Exception in thread "main" java.lang.IllegalStateException: The prefix q2 is not bound. 
  at org.apache.ws.commons.schema.SchemaBuilder.getRefQName(SchemaBuilder.java:822)
  at org.apache.ws.commons.schema.SchemaBuilder.getRefQName(SchemaBuilder.java:830)
  at org.apache.ws.commons.schema.SchemaBuilder.handleSimpleTypeUnion(SchemaBuilder.java:1767) 
  at org.apache.ws.commons.schema.SchemaBuilder.handleSimpleType(SchemaBuilder.java:626) 
  at org.apache.ws.commons.schema.SchemaBuilder.handleSchemaElementChild(SchemaBuilder.java:1505) 
  at org.apache.ws.commons.schema.SchemaBuilder.handleXmlSchemaElement(SchemaBuilder.java:658) 
  at org.apache.ws.commons.schema.SchemaBuilder.build(SchemaBuilder.java:156) at org.apache.ws.commons.schema.XmlSchemaCollection.read(XmlSchemaCollection.java:508) 
  at org.apache.ws.commons.schema.XmlSchemaCollection.read(XmlSchemaCollection.java:494)
{noformat}
Attached, the full source code can be found, UnionSerialization.java.

 

Is there anything that can be done to avoid this? 



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)

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