You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xml.apache.org by Johan 'Spocke' Sörlin <sp...@paregos.se> on 2000/02/23 11:46:25 UTC

Why can I get the validation to work??

I've used the IBM xml4j parser before and Iäm thinking of migrating to
Xerces but
I cant even make simple validation correctly, can some one help me???

Should'nt this code produce a parse error on a invalid document??


Java Source:
 org.apache.xerces.parsers.DOMParser parser = new
org.apache.xerces.parsers.DOMParser( );
  Document document;

  ((Configurable)
arser).setFeature( "http://xml.org/sax/features/validation", true );

  parser.setValidating( true );

  parser.parse("d:\\test.xml");

  document = parser.getDocument( );


tem.out.println( document.getDocumentElement( ).getFirstChild( ).getNodeName
( ) );


XML code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE document SYSTEM "document.dtd">
<document>
<title>bla bla</title>
<text>
bla bla bla
</text>
<ERROR>In valid element</ERROR>
</document>

______________________________________________
// -=: p a r e g o s : m e d i a d e s i g n :=-
// box 390 : S-931 24 skellefteå : sweden
// direct.tel: +46.(0)910.715705 : fax: +46.(0)910.715729
// http://www.paregos.se : js@paregos.se : ICQ: 9991973



Re: Why can I get the validation to work??

Posted by Eric Hodges <ha...@swbell.net>.
----- Original Message -----
From: "Andy Clark" <an...@apache.org>
To: <ge...@xml.apache.org>
Sent: Wednesday, February 23, 2000 5:25 PM
Subject: Re: Why can I get the validation to work??


> Johan 'Spocke' Sörlin wrote:
> > I've used the IBM xml4j parser before and Iäm thinking of
> > migrating to Xerces but I cant even make simple validation
> > correctly, can some one help me???
>
> You must register an ErrorHandler to receive notification of
> the validity errors.

I'm having trouble finding documentation that provides useful hints like
this one.  Where is it kept?

In general the documentation for Xalan is pretty bad.  I could really
benefit from an explanation of a lot of the terms used, like "connection".
And some examples of how to use it would go a long way.  It's far from
obvious how these tools should be used.




Re: Why can I get the validation to work??

Posted by Andy Clark <an...@apache.org>.
Johan 'Spocke' Sörlin wrote:
> I've used the IBM xml4j parser before and Iäm thinking of 
> migrating to Xerces but I cant even make simple validation 
> correctly, can some one help me???

You must register an ErrorHandler to receive notification of
the validity errors.

>   ((Configurable)parser).setFeature("http://xml.org/sax/features/validation", true );

Just a note, the Configurable interface has been removed in
the latest SAX2 beta. The latest version of Xerces (1.0.2)
supports the new SAX2 API, and therefore doesn't have the
Configurable interface.

-- 
Andy Clark * IBM, JTC - Silicon Valley * andyc@apache.org