Skip to Content.
Sympa Menu

xom-interest - [XOM-interest] Question about Base URI

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Arjan Huijzer <huijzer AT gmail.com>
  • To: xom-interest AT lists.ibiblio.org
  • Subject: [XOM-interest] Question about Base URI
  • Date: Thu, 18 Nov 2004 11:06:39 +0100

Hello,

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

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE person SYSTEM "person.dtd">
<person>
<firstname>Jan</firstname>
<lastname>Janssen</lastname>
</person>

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
File("c:/temp/person.xml"));
Document doc = parser.build(input);

} catch (Exception e) {
e.printStackTrace();
}
}
}

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
Source)
at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
Source)
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.




Archive powered by MHonArc 2.6.24.

Top of Page