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 Brett McLaughlin <br...@earthlink.net> on 2000/04/12 18:32:03 UTC

DOMParser and Validation

I posted this yesterday, and never heard anything.  I hate to be a nag,
but this is a major issue.  Help, anyone?

I must be really missing the boat here.  If I have this code:

try {
    DOMParser parser = new DOMParser();
    parser.setFeature("http://xml.org/sax/features/validation", true);
    parser.parse(new InputSource(in));
    Document doc = parser.getDocument();
} catch (Exception e) {
    e.printStackTrace();
}

and invoke it where in is a FileInputStream wrapping a local XML
document, which specifies a DTD that makes the document invalid, I get
absolutely no exceptions.  I can parse the same document with a SAX
Parser with validation on (and a registered ErrorHandler that gripes on
the error() callback), I get errors.  So why isn't validation for the
DOMParser letting me know something is invalid?

Thanks,
Brett

Re: DOMParser and Validation

Posted by Dirk Borowski <bo...@fokus.gmd.de>.
I think you first have to set the errorhandler with 

setErrorHandler() for the DOMParser.

Does it work ?

Greetings 
Dirk


Brett McLaughlin wrote:
> 
> I posted this yesterday, and never heard anything.  I hate to be a nag,
> but this is a major issue.  Help, anyone?
> 
> I must be really missing the boat here.  If I have this code:
> 
> try {
>     DOMParser parser = new DOMParser();
>     parser.setFeature("http://xml.org/sax/features/validation", true);
>     parser.parse(new InputSource(in));
>     Document doc = parser.getDocument();
> } catch (Exception e) {
>     e.printStackTrace();
> }
> 
> and invoke it where in is a FileInputStream wrapping a local XML
> document, which specifies a DTD that makes the document invalid, I get
> absolutely no exceptions.  I can parse the same document with a SAX
> Parser with validation on (and a registered ErrorHandler that gripes on
> the error() callback), I get errors.  So why isn't validation for the
> DOMParser letting me know something is invalid?
> 
> Thanks,
> Brett
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org

-- 
          	         >\ | /<
                       / (@  @ )\
+----------------------oOO-(_)-OOo--------------------------+
| Dirk Borowski             | Voice: +49 30 3463 7384       |
|                           | FAX:   +49 30 3463 8000       |
| GMD Fokus	            |                               |   
| Kaiserin-Augusta-Allee 31 | email: borowski@fokus.gmd.de  |
| D-10589 Berlin            | room: 2021                    |
|                           |                               |  
+---------------------------+-------------------------------+

RE: DOMParser and Validation

Posted by "George T. Joseph" <gt...@peakin.com>.
Did you call setErrorHandler() for the DOMParser?

-----Original Message-----
From: Brett McLaughlin [mailto:brettmclaughlin@earthlink.net]
Sent: Wednesday, April 12, 2000 12:32
To: xerces-j-dev@xml.apache.org
Subject: DOMParser and Validation


I posted this yesterday, and never heard anything.  I hate to be a nag,
but this is a major issue.  Help, anyone?

I must be really missing the boat here.  If I have this code:

try {
    DOMParser parser = new DOMParser();
    parser.setFeature("http://xml.org/sax/features/validation", true);
    parser.parse(new InputSource(in));
    Document doc = parser.getDocument();
} catch (Exception e) {
    e.printStackTrace();
}

and invoke it where in is a FileInputStream wrapping a local XML
document, which specifies a DTD that makes the document invalid, I get
absolutely no exceptions.  I can parse the same document with a SAX
Parser with validation on (and a registered ErrorHandler that gripes on
the error() callback), I get errors.  So why isn't validation for the
DOMParser letting me know something is invalid?

Thanks,
Brett

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org



RE: DOMParser and Validation

Posted by Dwayne Schultz <Dw...@Schultz.net>.
> From: Brett McLaughlin [mailto:brettmclaughlin@earthlink.net]
>
> and invoke it where in is a FileInputStream wrapping a local XML
> document, which specifies a DTD that makes the document invalid, I get
> absolutely no exceptions.  I can parse the same document with a SAX
> Parser with validation on (and a registered ErrorHandler that
> gripes on
> the error() callback), I get errors.  So why isn't validation for the
> DOMParser letting me know something is invalid?
>

I think the problem is you didn't register an ErrorHandler with the DOM
Parser.  It needs one just like the SAX Parser does.