You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Min Lee <mi...@hotmail.com> on 2001/07/31 20:27:00 UTC
JAXP problem
Hi all,
I'm having a strange problem with Xerces (1.3.1) and JAXP. It seems that if
I use the DOMParser.parse(String) to parse (with validation enabled)
data/personal-schema.xml, I have no problem. However, if I parse the same
file using DocumentBuilder API, it seems the parser cannot find the
personal.xsd and complains that the elements are not declared. I've seen
similar behaviour for SAXParser.
A snippet of my test program:
...
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setValidating(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(args[0]);
...
and the error, from the default error handler is:
Error: URI=file:///E:/personal-schema.xml Line=3: Element type "personnel"
must be declared.
I've seen this happen 1.4.1 release as well. Any ideas? Thanks in advance
for your help,
-ML
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org
Re: JAXP problem
Posted by Edwin Goei <ed...@sun.com>.
Min Lee wrote:
>
> Hi all,
>
> I'm having a strange problem with Xerces (1.3.1) and JAXP. It seems that if
> I use the DOMParser.parse(String) to parse (with validation enabled)
> data/personal-schema.xml, I have no problem. However, if I parse the same
> file using DocumentBuilder API, it seems the parser cannot find the
> personal.xsd and complains that the elements are not declared. I've seen
> similar behaviour for SAXParser.
>
> A snippet of my test program:
> ...
> DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
> dbf.setValidating(true);
> DocumentBuilder db = dbf.newDocumentBuilder();
> Document doc = db.parse(args[0]);
> ...
>
> and the error, from the default error handler is:
>
> Error: URI=file:///E:/personal-schema.xml Line=3: Element type "personnel"
> must be declared.
>
> I've seen this happen 1.4.1 release as well. Any ideas? Thanks in advance
> for your help,
OK, my initial evaluation was wrong, sorry. The problem is that you
need to turn on Namespace processing in the parser with JAXP. So for
example, before creating the DocumentBuilder, add this line:
dbf.setNamespaceAware(true);
The reason for this is historical. JAXP 1.0 defined the default value
to be false, then SAX 2.0 came along and defined a "namespaces" feature
with a default of true, then JAXP 1.1 came along and had to maintain
backward compatibility with JAXP 1.0. The reason it works if you use
Xerces implementation classes directly is because Xerces has a default
value of true.
So to summarize, I think what is going on here is that even though the
XSD file does not use a targetNamespace, the instance document must use
namespaces to point to the XSD file so the parser still needs to have
namespaces turned on. Hopefully someone will correct me if I am wrong.
-Edwin
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org
Re: JAXP problem
Posted by Edwin Goei <ed...@sun.com>.
Karen Fox wrote:
>
> This is a dumb question, but where can I find the xml-commons to get
> these new parsers? I looked at java.sun.com and www.apache.org and
> couldn't find them. I'm new to this stuff and don't understand what/how
> the CVS is or works. Thanks.
CVS is a common source code configuration management system used in open
source projects. See http://xml.apache.org/cvs.html for more info.
There is a web interface to CVS that you can access the files with on
the same page. xml-commons is not listed, but you can fiddle with an
existing URL to access it. BTW, the CVS interface seems to be down at
the moment.
-Edwin
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org
Re: JAXP problem
Posted by Karen Fox <kf...@mitre.org>.
This is a dumb question, but where can I find the xml-commons to get
these new parsers? I looked at java.sun.com and www.apache.org and
couldn't find them. I'm new to this stuff and don't understand what/how
the CVS is or works. Thanks.
Karen Fox
> Someone else reported a problem like this recently. I believe the
> problem is that the javax.xml.parsers code in xerces.jar is really old
> an out of date. The newest code is in the xml-commons repository under
> java/external/. You can check it out of CVS and place the resulting
> xml-apis.jar file before xerces.jar in your classpath and it should
> work. If you haven't already done so I'll try to check on it later
> today and get back with you.
>
> -Edwin
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org
Re: JAXP problem
Posted by Edwin Goei <ed...@sun.com>.
Min Lee wrote:
>
> Hi all,
>
> I'm having a strange problem with Xerces (1.3.1) and JAXP. It seems that if
> I use the DOMParser.parse(String) to parse (with validation enabled)
> data/personal-schema.xml, I have no problem. However, if I parse the same
> file using DocumentBuilder API, it seems the parser cannot find the
> personal.xsd and complains that the elements are not declared. I've seen
> similar behaviour for SAXParser.
>
> A snippet of my test program:
> ...
> DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
> dbf.setValidating(true);
> DocumentBuilder db = dbf.newDocumentBuilder();
> Document doc = db.parse(args[0]);
> ...
>
> and the error, from the default error handler is:
>
> Error: URI=file:///E:/personal-schema.xml Line=3: Element type "personnel"
> must be declared.
>
> I've seen this happen 1.4.1 release as well. Any ideas? Thanks in advance
> for your help,
Someone else reported a problem like this recently. I believe the
problem is that the javax.xml.parsers code in xerces.jar is really old
an out of date. The newest code is in the xml-commons repository under
java/external/. You can check it out of CVS and place the resulting
xml-apis.jar file before xerces.jar in your classpath and it should
work. If you haven't already done so I'll try to check on it later
today and get back with you.
-Edwin
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org