在Java中创建模式对象的问题
我有这个xsd:在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
<?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)));