2017-08-15 2 views
1

J'utilise Apache XmlSchema 2.2.1 pour analyser le schéma XSD. I a le schéma suivant:La partie locale ne peut pas être "nulle" lors de la création d'un QName

<?xml version="1.0" encoding="UTF-8"?> 
<xs:schema targetNamespace="http://www.example.com/aigu" 
     xmlns="http://www.example.com/aigu" 
     xmlns:xs="http://www.w3.org/2001/XMLSchema" 
     xmlns:jxb="http://java.sun.com/xml/ns/jaxb" jxb:version="2.0"> 
    <xs:attribute name="label" type="xs:string" /> 
    <xs:element name="object"> 
     <xs:complexType> 
      <xs:attribute ref="label" form="unqualified"/> 
     </xs:complexType> 
    </xs:element> 
</xs:schema> 

Le code suivant produit exception

import org.apache.ws.commons.schema.XmlSchemaCollection; 
import org.xml.sax.InputSource; 

import java.io.ByteArrayInputStream; 
import java.nio.charset.StandardCharsets; 

public class Aigu { 
    public static void main(String[] args) { 
     String schema = "HERE_IS_CONTENT_OF_SCHEMA"; 
     XmlSchemaCollection collection = new XmlSchemaCollection(); 
     collection.read(new InputSource(new ByteArrayInputStream(schema.getBytes(StandardCharsets.UTF_8)))); 
    } 
} 

Stacktrace:

Exception in thread "main" java.lang.IllegalArgumentException: local part cannot be "null" when creating a QName 
    at javax.xml.namespace.QName.<init>(QName.java:244) 
    at javax.xml.namespace.QName.<init>(QName.java:188) 
    at org.apache.ws.commons.schema.utils.XmlSchemaNamedWithFormImpl.setName(XmlSchemaNamedWithFormImpl.java:117) 
    at org.apache.ws.commons.schema.utils.XmlSchemaNamedWithFormImpl.setForm(XmlSchemaNamedWithFormImpl.java:105) 
    at org.apache.ws.commons.schema.XmlSchemaAttribute.setForm(XmlSchemaAttribute.java:170) 
    at org.apache.ws.commons.schema.SchemaBuilder.handleAttribute(SchemaBuilder.java:959) 
    at org.apache.ws.commons.schema.SchemaBuilder.handleAttribute(SchemaBuilder.java:923) 
    at org.apache.ws.commons.schema.SchemaBuilder.handleComplexType(SchemaBuilder.java:307) 
    at org.apache.ws.commons.schema.SchemaBuilder.handleElement(SchemaBuilder.java:420) 
    at org.apache.ws.commons.schema.SchemaBuilder.handleSchemaElementChild(SchemaBuilder.java:1512) 
    at org.apache.ws.commons.schema.SchemaBuilder.handleXmlSchemaElement(SchemaBuilder.java:659) 
    at org.apache.ws.commons.schema.SchemaBuilder.build(SchemaBuilder.java:157) 
    at org.apache.ws.commons.schema.XmlSchemaCollection.read(XmlSchemaCollection.java:508) 
    at org.apache.ws.commons.schema.XmlSchemaCollection.read(XmlSchemaCollection.java:717) 
    at org.apache.ws.commons.schema.XmlSchemaCollection.read(XmlSchemaCollection.java:565) 
    at com.netcracker.mediation.transition.model.xmltojava.Aigu.main(Aigu.java:23) 

Est-ce un bug dans le code Apache ou mon schéma est incorrect?

Répondre

1

L'attribut form ne peut pas être utilisé dans une utilisation d'attribut ayant un ref (comme contraint au point 3.2 de this paragraph of the XML Schema specification). De plus, puisque la cible de la référence est une déclaration d'attribut de niveau supérieur dans un schéma avec un espace de noms cible, son form, s'il était autorisé à le mettre explicitement, devrait être qualified.

Il peut expliquer l'erreur, car la trace semble indiquer que cela se produit là.

Ce serait le schéma corrigé:

<?xml version="1.0" encoding="UTF-8"?> 
<xs:schema targetNamespace="http://www.example.com/aigu" 
    xmlns="http://www.example.com/aigu" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    xmlns:jxb="http://java.sun.com/xml/ns/jaxb" jxb:version="2.0"> 
    <xs:attribute name="label" type="xs:string" /> 
    <xs:element name="object"> 
     <xs:complexType> 
      <xs:attribute ref="label"/> 
     </xs:complexType> 
    </xs:element> 
</xs:schema> 
+0

Merci beaucoup! –