You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Jo...@sanofi-aventis.com on 2007/08/14 18:46:00 UTC
The markup declarations contained or pointed to by the document type declaration must be well-formed.
Hello,
I have an XML document which has a DOCTYPE tag referencing a DTD.
Instead I want to reference an XSD which specifies this document
structure. I use the XMLCatalogResolver to detect the publicId in the
DOCTYPE and replace it with a URI pointing to the XSD. I think this
part is working, however I get an error during the sax parsing: "The
markup declarations contained or pointed to by the document type
declaration must be well-formed." I believe the XML is well-formed
because if I omit the DOCTYPE tag from the XML document the parsing
occurs without error. The namespace in the XSD is
"http://www.ncbi.nlm.nih.gov" and I don't have any reference to
namespace in the XML document. Is this what the error is refering to?
[shiporder.xml]
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE shiporder PUBLIC "-//NCBI//NCBI Entrezgene/EN"
"NCBI_Entrezgene.dtd">
<shiporder orderid="889923">
<orderperson>John Smith</orderperson>
<shipto>
<name>Ola Nordmann</name>
<address>Langgt 23</address>
<city>4000 Stavanger</city>
<country>Norway</country>
</shipto>
<item>
<title>Empire Burlesque</title>
<note>Special Edition</note>
<quantity>1</quantity>
<price>10.90</price>
</item>
<item>
<title>Hide your heart</title>
<quantity>1</quantity>
<price>9.90</price>
</item>
</shiporder>
[shiporder.xsd]
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.ncbi.nlm.nih.gov"
targetNamespace="http://www.ncbi.nlm.nih.gov"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:element name="shiporder">
<xs:complexType>
<xs:sequence>
<xs:element name="orderperson" type="xs:string"/>
<xs:element name="shipto">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="address" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="item" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="note" type="xs:string" minOccurs="0"/>
<xs:element name="quantity" type="xs:positiveInteger"/>
<xs:element name="price" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="orderid" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
[catalog.xml]
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE catalog PUBLIC "-//OASIS//DTD Entity Resolution XML Catalog
V1.0//EN"
"http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd">
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog"
prefer="public">
<public publicId="-//NCBI//NCBI Entrezgene/EN"
uri="file:///c:/data/sample/shiporder.xsd"/>
</catalog>
[code]
File schemaLocation = new File("file:///c:/data/sample/shiporder.xsd");
Schema schema = factory.newSchema(schemaLocation);
String [] catalogs = {"file:///C:/data/sample/catalog.xml"};
XMLCatalogResolver resolver = new XMLCatalogResolver();
resolver.setPreferPublic(true);
resolver.setCatalogList(catalogs);
saxParser.getXMLReader().setProperty("http://apache.org/xml/properties/i
nternal/entity-resolver", resolver);
try {
saxParser.getXMLReader().parse("C:/data/sample/shiporder.xml");
} catch (SAXParseException e) {
e.printStackTrace();
}
[stacktrace]
SchemaFactoryImpl$1.error(SAXParseException) line: not available
ErrorHandlerWrapper.error(String, String, XMLParseException) line: not
available
XMLErrorReporter.reportError(XMLLocator, String, String, Object[],
short) line: not available
XMLErrorReporter.reportError(String, String, Object[], short) line: not
available
XSDHandler.reportSchemaError(String, Object[], Element) line: not
available
XSDHandler.getSchema(String, Source, boolean, short, Element) line: not
available
XSDHandler.parseSchema(Source, XSDDescription, Hashtable) line: not
available
XMLSchemaLoader.loadSchema(XSDDescription, Source, Hashtable) line: not
available
XMLSchemaLoader.loadGrammar(Source) line: not available
SchemaFactoryImpl.newSchema(Source[]) line: not available
SchemaFactoryImpl(SchemaFactory).newSchema(Source) line: not available
SchemaFactoryImpl(SchemaFactory).newSchema(File) line: not available
EntrezGeneParserDriver.main(String[]) line: 86
TIA,
John
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org
Re: The markup declarations contained or pointed to by the document type
declaration must be well-formed.
Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi John,
<Jo...@sanofi-aventis.com> wrote on 08/14/2007 12:46:00 PM:
> Hello,
>
> I have an XML document which has a DOCTYPE tag referencing a DTD.
> Instead I want to reference an XSD which specifies this document
> structure. I use the XMLCatalogResolver to detect the publicId in the
> DOCTYPE and replace it with a URI pointing to the XSD.
You can't replace the DTD with a schema. Whatever you return from this
call to the resolver needs to be a DTD (in other words must match [1] the
extSubset [2] production from the XML 1.0 specification) or null if you
want the parser to use its default resolution mechanism.
> I think this
> part is working, however I get an error during the sax parsing: "The
> markup declarations contained or pointed to by the document type
> declaration must be well-formed." I believe the XML is well-formed
> because if I omit the DOCTYPE tag from the XML document the parsing
> occurs without error. The namespace in the XSD is
> "http://www.ncbi.nlm.nih.gov" and I don't have any reference to
> namespace in the XML document. Is this what the error is refering to?
If your schema has a target namespace and your instance document declares
no namespaces you need to change one of them in order for your document to
be valid. Either add a namespace declaration to the instance document or
remove the target namespace from the schema document.
<snip/>
> TIA,
> John
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org
Thanks.
[1] http://www.w3.org/TR/2006/REC-xml-20060816/#ExtSubset
[2] http://www.w3.org/TR/2006/REC-xml-20060816/#NT-extSubset
Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org