Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Java中创建模式对象的问题_Java_Xml_Xsd_Schema - Fatal编程技术网

在Java中创建模式对象的问题

在Java中创建模式对象的问题,java,xml,xsd,schema,Java,Xml,Xsd,Schema,我有这个xsd: <?xml version="1.0" encoding="ISO-8859-1" ?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="shiporder"> <xsd:complexType> <xsd:sequence> <xsd:element name="orderpers

我有这个xsd:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<xsd:element name="shiporder">
  <xsd:complexType>
    <xsd:sequence>
      <xsd:element name="orderperson" type="xsd:string"/>
      <xsd:element name="shipto">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element name="name" type="xsd:string"/>
            <xsd:element name="address" type="xsd:string"/>
            <xsd:element name="city" type="xsd:string"/>
            <xsd:element name="country" type="xsd:string"/>
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
      <xsd:element name="item" maxOccurs="unbounded">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element name="title" type="xsd:string"/>
            <xsd:element name="note" type="xsd:string" minOccurs="0"/>
            <xsd:element name="quantity" type="xsd:positiveInteger"/>
            <xsd:element name="price" type="xsd:decimal"/>
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
    </xsd:sequence>
    <xsd:attribute name="orderid" type="xsd:string" use="required"/>
  </xsd:complexType>
</xsd:element>

</xsd:schema>
我在创建新架构实例时遇到此错误:

SCHEMA : schema_reference.4: Failed to read schema document '...', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
为此:

Schema schema = schemaFactory.newSchema(new StreamSource(new StringReader(xsd)));
Schema schema = schemaFactory.newSchema(new StreamSource(xsd));
Schema schema = schemaFactory.newSchema(new StreamSource(new StringReader(xsd)));