Jump to content

Writing XML with SAX with VALIDATION?

Recommended Posts

Hello,is it possible to create an XML file with SAX with Validation (using an xsd)? I know it is possible to read an XML file with SAX with Validation and to write an XML file with SAX. But now I want to create a valid XML file with SAX.Writing with SAX I do like this:

public class SaxWriter { 		public static void main(String[] args) {		try{FileOutputStream fileOutputStream=new FileOutputStream("C:/_develop/asja/lib/local/saxxmlliblocal/properties/xml/catalogueSAXWithoutValidation.xml");			OutputFormat outputFormat=new OutputFormat("XML","ISO-8859-1",false);			outputFormat.setIndent(0); 			XMLSerializer xmlSerializer=new XMLSerializer(fileOutputStream,outputFormat);		               ContentHandler contentHandler= xmlSerializer.asContentHandler();			Catalogue catalogue=getCatalogue(10,10);			writeXMLFile(contentHandler,catalogue);			fileOutputStream.close();		}catch (Exception e) {			e.printStackTrace();		}}public static void writeXMLFile(ContentHandler contentHandler,Catalogue catalogue){				try{		contentHandler.startDocument();		contentHandler.startElement("", "", "catalogue", null);		contentHandler.startElement("", "", "date_created", null);                                     *…*		contentHandler.endElement("", "", "cds");		contentHandler.endElement("", "", "catalogue");		contentHandler.endDocument();		}catch (SAXException saxException){			saxException.printStackTrace();					}	}}

I can write the XML file and than read it with validation, but I want to avoid reading the XML-file again.Regards,Katja

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...