2017-08-15 1 views
1

Apache XmlSchema 2.2.1を使用してXSDスキーマを解析します。私は、次のスキーマを持っていますQNameを作成するときにローカル部分を "null"にすることはできません

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

次のコードは、スタックトレース例外

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)))); 
    } 
} 

を生成します。

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) 

が、それはApacheのコードのバグですか、私のスキーマが無効ですか?

答えて

1

属性formは、ref(ポイント3.2で制限されているように、this paragraph of the XML Schema specification)の属性の使用では使用できません。

また、ターゲットの名前空間を持つスキーマの参照先が、formであるため、明示的に配置することができる場合は、qualifiedにする必要があります。

トレースにはトレースがあるので、エラーが説明されることがあります。

これは修正されたスキーマのようになります。

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

はどうもありがとうございました! –

関連する問題