0

jing を使用して、複数の名前空間、複数のスキーマ xml を検証しようとしています。私のファイルは次のとおりです:
testtype.xsd

<?xml version="1.0" encoding="utf-8"?>
 <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        targetNamespace="http://www.my.com/testtype"
        xmlns:abcs="http://www.my.com/test1"
        xmlns:childs="http://www.my.com/childs">

 <xsd:import namespace="http://www.my.com/test1" 
       schemaLocation="abc.xsd"/>
 <xsd:import namespace="http://www.my.com/childs"
       schemaLocation="child.xsd"/>

<xsd:complexType name="testtype">
 <xsd:sequence>
   <xsd:element ref="childs:team" />
   <xsd:element ref="abcs:test"/>
 </xsd:sequence>
</xsd:complexType>
</xsd:schema>  

子.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
targetNamespace="http://www.my.com/childs"
xmlns:why="http://www.my.com/childs">

<xs:include schemaLocation="parent.xsd" />
<xs:element name="team" type="why:baseTeam"/>
</xs:schema>  

abc.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    targetNamespace="http://www.my.com/test1" >

<xs:element name="test" type="xs:string">
</xs:element>
</xs:schema>  

親.xsd

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://www.my.com/childs"
    xmlns:whys="http://www.my.com/childs">

<xsd:include schemaLocation="grandparent.xsd" />
<xsd:complexType name="baseTeam">
 <xsd:attribute name="mascot" type="whys:mascotNames" use="required" />
</xsd:complexType>
</xsd:schema>

祖父母.xsd

<?xml version="1.0" encoding="utf-8"?>
 <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    targetNamespace="http://www.my.com/childs">

<xsd:simpleType name="mascotNames">
<xsd:restriction base="xsd:string">
  <xsd:enumeration value="bengals" />
  <xsd:enumeration value="cowboys" />
  <xsd:enumeration value="patriots" />
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>  

サンプル.xml

<?xml version="1.0"?>
<testtype xmlns="http://www.my.com"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

            xsi:schemaLocation="http://www.my.com/testtype  testtype.xsd
                http://www.my.com/childs  child.xsd
                                http://www.my.com/test1 abc.xsd"
            xmlns:testtype="http://www.my.com/testtype"
                xmlns:childs="http://www.my.com/childs"
            xmlns:abcs="http://www.my.com/abcs">

<childs:team mascot="cowboys"/>
<abcs:test>statement</abcs:test>
</testtype>

子は親から型を取得し、親は祖父母から型を取得します。abc は独立した名前空間です。testtype には、child と abc の両方が含まれます。問題は、sample.xml を testtype.xsd に対して検証しようとすると、null ポインター例外が発生することです。

Exception in thread "main" java.lang.NullPointerException
at org.apache.xerces.impl.xs.XMLSchemaLoader.resolveDocument(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.findSchemaGrammar(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)

null ポインター例外が発生する理由、または xsd の構成に問題があるかどうかを教えてください。

ありがとう

4

0 に答える 0