[XOM-interest] Question about Base URI

Arjan Huijzer huijzer at gmail.com
Thu Nov 18 05:06:39 EST 2004


I have the following XML document that I want to parse:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE person SYSTEM "person.dtd">

The DTD that is used contains the following lines:

<!ELEMENT person (firstname, lastname)>
<!ELEMENT firstname (#PCDATA)>
<!ELEMENT lastname (#PCDATA)>

The java code I use to parse this document is the following:

import java.io.*;
import nu.xom.*;

public class Test {

    public static void main(String[] args) {
        try {
            Builder parser = new Builder();
            FileInputStream input = new FileInputStream(new
            Document doc = parser.build(input);
        } catch (Exception e) {

When I run this code I get an Exception:
java.io.FileNotFoundException: C:\eclipse\workspace\XOM\person.dtd
(The system cannot find the file specified)
	at java.io.FileInputStream.open(Native Method)
	at java.io.FileInputStream.<init>(Unknown Source)
	at java.io.FileInputStream.<init>(Unknown Source)
	at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
	at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
	at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
	at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown Source)
	at org.apache.xerces.impl.XMLEntityManager.startDTDEntity(Unknown Source)
	at org.apache.xerces.impl.XMLDTDScannerImpl.setInputSource(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentScannerImpl$DTDDispatcher.dispatch(Unknown
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
	at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
	at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
	at nu.xom.Builder.build(Unknown Source)
	at nu.xom.Builder.build(Unknown Source)
	at examples.Test.main(Test.java:12)

When I modify my code so that the build method gets a second parameter
(base URI), everything works:

Document doc = parser.build(input, "file:///c:/temp/");

Why is this second parameter necessary? Can't the parser deduct the
base URI from the filename of the XML file?

Thanks in advance for any help!

Arjan Huijzer
The Netherlands

p.s. I use the latest Xerces release (2.6.2) and my operating system
is Windows NT Workstation.

More information about the XOM-interest mailing list