Title: An XML Doc without a DTD specification but use SetSystemId( Sring ) before parsing

Hi:

Our application stores it data model into an XML file. We are using the SAX parser that comes with Xerces 1.2.1. I have inherited the code that writes and parses the XML file that our application read and writes. Currently the DTD path is specified in the XML file as an URL that is an absolute path. See below:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Root PUBLIC "-//Innovance Networks, Inc.//Framework XML Service//EN"
                      "file:/D:/MyProjects/planning/planning0385/nt4/config/piCOM.dtd">
<Root ID="root">
    <Root.networks>
        <Network ID="mem_4">
            <ModelObject.Name>0</ModelObject.Name>

... lots of stuff deleted ...

The absolute path is a problem as our customers will definitely install our product in different directories on their PC.

Our application is a stand alone PC App that does absolutely nothing over the Internet. Therefore I would like to specify the location of the DTD file when reading in the XML file

So far I have tried the following:

I did not specify the DTD URL when writing the XML file in my Java code: 

outputFormat.setDoctype(PUBLIC_ID, null );

The top of the XML file looks like:

<?xml version="1.0" encoding="UTF-8"?>
<Root ID="root">
    <Root.networks>
        <Network ID="mem_4">
            <ModelObject.Name>0</ModelObject.Name>
... lots of stuff deleted ...

When reading the XML file in my Java code I set location of the DTD:

source.setSystemId( dtdUrl.toString() );  
parser.parse(source);                             // NOTE: source is org.xml.sax.InputSource;

Unfortunalety I get a SAX parse error:

Validating and loading XML file: file:/D:/TestProperties/Qwest_OCH.pdm
Parsing exception, Column number: 17
Parsing exception, Line number:   2
Parsing exception, Public ID:     null
Parsing exception, System ID:     file:/D:/MyProjects/planning/planning0385/nt4/config/piCOM.dtd
Parsing exception:                org.xml.sax.SAXParseException: Element type "Root" must be declared.

I believe the DOCTYPE is missing. If so how do you specify a DOCTYPE without the dtd?
Does setting the SystemId( String) in the Java code have precedence over what is in the XML file?

If I could actually avoid using a DTD all together that would be even better. .. ie skip validation

Any help would be appreciated. (my knowledge of XML is very small)

Regards,
Rodger Lucas           
AgileCore(tm), Planning & Eng Center Dev - SW Designer
Innovance Networks Inc  ( 613.728.3757 ext 4358
19 Fairmont Ave.                       2  613.728.1590
Ottawa, Ontario, Canada       * [EMAIL PROTECTED]
K1Y 1X4


Reply via email to