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 "K. Venugopal" <k....@sun.com> on 2003/05/05 18:05:18 UTC

Re: Validating text to xml conversion

HI Barbal ,
please find my  views inline .


Barbal Rubio, Lluis wrote:

>Hi,
>
>I'm creating a program that parses a text file and uses its data to create
>an xml file. The xml file is defined by an XML schema.
>
>Using a sample I've found in Internet, I've decided to develop the following
>solution: I've created a text parser that generates SAX events; the SAX
>events are received by a transformer that generates an XML file.
>
>I've got a couple of problems I'm not able to fix, so I ask you for some
>help.
>
>FIRST PROBLEM
>--------------------------
>
>I generate a xml file that defines a DTD for validation instead of an XML
>schema. How can I define an XML Schema? I include a snippet of mi code.
>
>			SAXTransformerFactory fact = (SAXTransformerFactory)SAXTransformerFactory.newInstance();
>			TransformerHandler hd =fact.newTransformerHandler();
>			Transformer serializer = hd.getTransformer();
>			serializer.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1");
>	
>			serializer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "ProvaSli.xsd");
>			serializer.setOutputProperty(OutputKeys.INDENT,"yes");
>			StreamResult streamResult = new StreamResult(outputFile);
>			hd.setResult(streamResult);
>
    I believe this problem  can  be solved in two ways.  construct a 
input stream from the output stream of a transformer and pass it  to a 
schema validating parser( You need to set schema language and schema 
source properties to enable a
parser to validate against a schema , please refer to  
http://xml.apache.org/xerces2-j/features.html for more details) .
May be another way to solve your problem is  to generate XNI events 
instead of SAX events and configuring schema validator in the pipleline .



>SECOND PROBLEM
>------------------------------
>
>The XML I generate is not validated against the XML schema. I would like to
>validate the resulting XML file while I'm generating it, that is, I don't
>want to validate it after the generation. How can I do it?
>
>Please, ask me if you need further information or code (or you do not
>understand my foreigner's English).
>
>Thanks in advance
>
>
>
>Lluis Barbal i Rubio
>
>
>***************************************************************************
>
>DISCLAIMER: Este mensaje contiene información propietaria 
>de la cual parte o toda puede contener información confidencial
>o protegida legalmente. Esta exclusivamente destinado al 
>usuario de destino.
>Si, por un error de envio o transmisión, ha recibido este mensaje 
>y usted no es el destinatario del mismo, por favor, notifique
>de este hecho al remitente.
>Si no es el destinatario final de este mensaje no debe usar, 
>informar, distribuir, imprimir, copiar o difundir este mensaje 
>bajo ningún medio.
>
>---------
>
>DISCLAIMER: This e-mail contains propietary information some 
>or all of which may be legally privileged. It is for the intended 
>recipient only. If an addressing or transmission error has 
>misdirected this e-mail, please notify the author by replying to
>this e-mail. If you are not the intended recipient you must not use,
>disclose, distribute, copy, print or rely on this e-mail.
>
>***************************************************************************
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
>For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>
>  
>