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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to