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 Paul A Jungwirth <pj...@juno.com> on 2002/02/25 00:33:44 UTC
InputSouce(InputStream) and DTDs
Hi all,
I noticed in 1.4.4 that when I'm parsing an XML document with a DTD, the
way I create the InputSource for the original document determines whether
the parser can find the DTD. That is, say my XML document, called
"my-xml-doc.xml," includes this line:
<!DOCUMENT my-xml-doc SYSTEM "my-xml-doc.dtd">
And say my-xml-doc.xml and my-xml-doc.dtd live in the same directory.
Now, this code works fine:
SAXParser p = new SAXParser();
p.setContentHander(this);
p.parse(new InputSource("my-xml-doc.xml"));
But this code can't find the DTD:
SAXParser p = new SAXParser();
p.setContentHandler(this);
p.parse(new InputSource(new FileInputStream("my-xml-doc.xml")));
I was looking through the Xerces source, and I found that at line 754 of
DefaultEntityHandler, fSystemId in the first case is
"file:///full/path/my-xml-doc.dtd," but in the second case it's just
"my-xml-doc.dtd." Then that's the string that's used to create an
InputSource for the DTD.
That raises two questions:
1) How come fSystemId is different depending on whether I pass an
InputSource from a filename rather than an InputStream? Is it because
with the filename, the InputSource has some context information that it
lacks when it just gets a stream? And then the parser uses that context
information for clues on the DTD? That would make sense to me. But I can
think of no answer to my second question:
2) Even *if* fSystemId is different in each case, how come the simple
string "my-xml-doc.dtd" prevents the parser from finding the DTD? The
simple string "my-xml-doc.xml" didn't prevent the parser from finding the
XML document.
Either general answers or suggestions on where in the source I should
look would be welcome.
Thanks,
Paul Jungwirth
________________________________________________________________
GET INTERNET ACCESS FROM JUNO!
Juno offers FREE or PREMIUM Internet access for less!
Join Juno today! For your FREE software, visit:
http://dl.www.juno.com/get/web/.
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
RE: InputSouce(InputStream) and DTDs
Posted by Keith Chew <ke...@jungledrum.co.nz>.
Hi Paul
I have a similar problem with including XML files (see previous post with
subject "include file...").
<?xml version="1.0"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts
Configuration 1.0//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd" [
<!ENTITY part1 SYSTEM "file:part1.xml">
<!ENTITY part2 SYSTEM "file:part2.xml">
<!ENTITY part3 SYSTEM "file:part3.xml">
]>
It works on absolute path, but not relative.
Keith
-----Original Message-----
From: Paul A Jungwirth [mailto:pjungwirth@juno.com]
Sent: Monday, 25 February 2002 12:34 p.m.
To: xerces-j-user@xml.apache.org
Subject: InputSouce(InputStream) and DTDs
Hi all,
I noticed in 1.4.4 that when I'm parsing an XML document with a DTD, the
way I create the InputSource for the original document determines whether
the parser can find the DTD. That is, say my XML document, called
"my-xml-doc.xml," includes this line:
<!DOCUMENT my-xml-doc SYSTEM "my-xml-doc.dtd">
And say my-xml-doc.xml and my-xml-doc.dtd live in the same directory.
Now, this code works fine:
SAXParser p = new SAXParser();
p.setContentHander(this);
p.parse(new InputSource("my-xml-doc.xml"));
But this code can't find the DTD:
SAXParser p = new SAXParser();
p.setContentHandler(this);
p.parse(new InputSource(new FileInputStream("my-xml-doc.xml")));
I was looking through the Xerces source, and I found that at line 754 of
DefaultEntityHandler, fSystemId in the first case is
"file:///full/path/my-xml-doc.dtd," but in the second case it's just
"my-xml-doc.dtd." Then that's the string that's used to create an
InputSource for the DTD.
That raises two questions:
1) How come fSystemId is different depending on whether I pass an
InputSource from a filename rather than an InputStream? Is it because
with the filename, the InputSource has some context information that it
lacks when it just gets a stream? And then the parser uses that context
information for clues on the DTD? That would make sense to me. But I can
think of no answer to my second question:
2) Even *if* fSystemId is different in each case, how come the simple
string "my-xml-doc.dtd" prevents the parser from finding the DTD? The
simple string "my-xml-doc.xml" didn't prevent the parser from finding the
XML document.
Either general answers or suggestions on where in the source I should
look would be welcome.
Thanks,
Paul Jungwirth
________________________________________________________________
GET INTERNET ACCESS FROM JUNO!
Juno offers FREE or PREMIUM Internet access for less!
Join Juno today! For your FREE software, visit:
http://dl.www.juno.com/get/web/.
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org