katja.radelicki@colruyt.be Posted October 8, 2008 Share Posted October 8, 2008 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 Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.