Hi Edwin,
Using DocumentBuilderFactory.setNamespaceAware(true) fixes the problem.
Thanks for your help!
ML
> >
> > 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: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]