You could do it with a parser like Xerces. (xml.apache.org)

public void parseXml(String xml) throws SAXException, IOException{
                 try {
                        XMLReader parser = XMLReaderFactory.createXMLReader(
"org.apache.xerces.parsers.SAXParser");
                        parser.setContentHandler(this.xmlConsumer);
                        parser.setErrorHandler(this);
                        try {
                                        //if (validate && parser instanceof
XMLReader)
                                        if ( parser instanceof XMLReader ){
        
((XMLReader)parser).setFeature( "http://xml.org/sax/features/validation";,
true
        
((XMLReader)parser).setFeature( "http://xml.org/sax/features/namespaces";,
true
        
((XMLReader)parser).setFeature("http://apache.org/xml/features/validation/sc
hema",true );
        
((XMLReader)parser).setFeature(
"http://apache.org/xml/features/nonvalidating/load-external-dtd";,
        
true );
        
((XMLReader)parser).setFeature(
"http://apache.org/xml/features/validation/schema-full-checking";,
        
true );

                                        }
                        } catch (Exception ex) {
                        }
                        parser.parse(new InputSource( new StringReader(xml))
);
                        } catch (org.xml.sax.SAXParseException spe) {
                                spe.printStackTrace(System.err);
      }

        }

You have to do the right import etc..

regards,

Edgar
-----Oorspronkelijk bericht-----
Van: Sorin Marti [mailto:[EMAIL PROTECTED]]
Verzonden: vrijdag 19 april 2002 11:23
Aan: [EMAIL PROTECTED]
Onderwerp: Newbie Question


Hello toghether

I'm a XML newbie and a Cocoon newbie, too...

I wrote an example XML File and the appropriate XML schema.
How to validate the XML File? (I guess I have to validate it because
there are rules that you can't fill in this or that in a certain element...

every advice would be helpful...

thanks in advance mas


---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <[EMAIL PROTECTED]>
For additional commands, e-mail: <[EMAIL PROTECTED]>

---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <[EMAIL PROTECTED]>
For additional commands, e-mail: <[EMAIL PROTECTED]>

Reply via email to