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 Torsten Curdt <tc...@managesoft.com> on 2004/10/08 12:59:55 UTC

validating parser an documents without a dtd

I have a validating parser but no DTD
or DTD reference inside the document.
But I want to require validation! So..

1) how do I tell the parser to fail if
there is no DTD

2) how do I specify a *specific* DTD/Schema
the InputSource has to comply to?

Currently I use the following code...

         SAXParserFactory spf = SAXParserFactory.newInstance();
         spf.setNamespaceAware(true);
         spf.setValidating(validating);
         SAXParser saxParser = spf.newSAXParser();
         XMLReader xmlReader = saxParser.getXMLReader();
         xmlReader.setContentHandler(handler);
         xmlReader.setErrorHandler(handler);
         xmlReader.setDTDHandler(handler);
         xmlReader.setEntityResolver(myresolver);
         xmlReader.parse(new InputSource(is));

cheers
--
Torsten

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


RE: validating parser an documents without a dtd

Posted by "Ganesh Babu Nallamothu, Integra-India" <ga...@integra-india.com>.
change the code like the following

spf.setValidating(true);

Ganesh


-----Original Message-----
From: Torsten Curdt [mailto:tcurdt@managesoft.com]
Sent: Friday, October 08, 2004 4:30 PM
To: xerces-j-user@xml.apache.org
Subject: validating parser an documents without a dtd


I have a validating parser but no DTD
or DTD reference inside the document.
But I want to require validation! So..

1) how do I tell the parser to fail if
there is no DTD

2) how do I specify a *specific* DTD/Schema
the InputSource has to comply to?

Currently I use the following code...

         SAXParserFactory spf = SAXParserFactory.newInstance();
         spf.setNamespaceAware(true);
         spf.setValidating(validating);
         SAXParser saxParser = spf.newSAXParser();
         XMLReader xmlReader = saxParser.getXMLReader();
         xmlReader.setContentHandler(handler);
         xmlReader.setErrorHandler(handler);
         xmlReader.setDTDHandler(handler);
         xmlReader.setEntityResolver(myresolver);
         xmlReader.parse(new InputSource(is));

cheers
--
Torsten

---------------------------------------------------------------------
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


new parser for users

Posted by "Ganesh Babu Nallamothu, Integra-India" <ga...@integra-india.com>.
Dear All,

I am new to java. I have taken some examples and trying to write one parser
which parse the files based on catalog files. Everything is working fine.
But I need to set ErrorHandler and Locator. So that I can get the error
message like this.

filename.xml:linenumber:columnnumber:message.

Please see my code and let me know where I am going wrong.

import java.io.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
import javax.xml.parsers.*;
import org.apache.xml.resolver.tools.*;

public class gae extends DefaultHandler{

    public static void main(String[] args) {
	String uri = args[0];
	try {
	    SAXParserFactory factory = SAXParserFactory.newInstance();
	    factory.setNamespaceAware(true);
	    factory.setValidating(true);
	    SAXParser parser = factory.newSAXParser();
	    XMLReader reader = parser.getXMLReader();
	    reader.setEntityResolver(new CatalogResolver());
	    reader.setErrorHandler(handler);
	    reader.setDocumentLocator();
	    reader.parse(uri);
	}
	catch (IOException e){}
	catch (ParserConfigurationException e){}
	catch (SAXException
e){System.out.println(uri+":"+":"+e.getLineNumber()+":"+e.getColumnNumber()+
":"+e.getMessage());}
    }

}

Ganesh


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