You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by José Antonio Pérez Testa <ja...@indra.es> on 2004/06/01 11:42:45 UTC

Re: AW: AW: [Digester] using Schema Validation

Eureka! I've finally found a solution,
First, I tryed your example with no complaints from Digester.
Then I enabled log from org.apache.commons which was disabled before 
(ugly thing when debugging  :( ) ,
and I found the exception being catched and logged but not throwed .
Finally, I added an ErrorHandler to Digester in order to be able to know 
when an error was been generated
and my problem was solved.

Thanks a lot Reidar!
Regards,
Testa
Reidar Hörning wrote:

>Hello,
>
>maybe you can find a solution for your problem looking at the following
>example files and comparing it with yours. These examples are working in
>my environment.
>
>XSD-file: 
>
><?xml version="1.0" encoding="UTF-8"?>
><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
>  <xsd:element name="X">
>    <xsd:complexType>
>      <xsd:choice maxOccurs="unbounded">
>        <xsd:element name="A">
>          <xsd:complexType>
>            <xsd:sequence maxOccurs="unbounded">
>              <xsd:element name="Z" type="xsd:string"/>
>            </xsd:sequence>
>          </xsd:complexType>
>        </xsd:element>
>        <xsd:element name="B">
>          <xsd:complexType>
>            <xsd:attribute name="BAtt" type="xsd:string"
>use="optional"/>
>          </xsd:complexType>
>        </xsd:element>
>      </xsd:choice>
>    </xsd:complexType>
>  </xsd:element>
></xsd:schema>
>
>XML-file:
>
><?xml version="1.0" encoding="UTF-8"?>
><X xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
>  <A>
>    <Z ZAtt="unrecognized fault">content</Z>
>  </A>
>  <B BAtt="content" BAtt2="recognized fault"/>
>  <C/><!--recognized fault tag -->
></X>
>
>Have a closer look at the Attribute ZAtt. This is, instead of the
>B-tag-Attribute BAtt2, not recognized by Xerces-Schema-Validation.
>
>Using the suggested code I get e.g.:
>
>org.apache.commons.digester.Digester error
>SCHWERWIEGEND: Parse Error at line 7 column 6: cvc-complex-type.2.4.a:
>Invalid content was found starting with element 'C'. One of '{"":A,
>"":B}' is expected.
>org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content
>was found starting with element 'C'. One of '{"":A, "":B}' is expected.
>...
>
>and
>31.05.2004 18:20:19 org.apache.commons.digester.Digester error
>SCHWERWIEGEND: Parse Error at line 6 column 46: cvc-complex-type.3.2.2:
>Attribute 'BAtt2' is not allowed to appear in element 'B'...
>
>Regards
>Reidar
>
>-----Ursprüngliche Nachricht-----
>Von: José Antonio Pérez Testa [mailto:japtesta@indra.es] 
>Gesendet: Montag, 31. Mai 2004 16:50
>An: Jakarta Commons Users List
>Betreff: Re: AW: [Digester] using Schema Validation
>
>
>In fact I am migrating from a SAXBuilder build returning a Document to a
>
>Digester parse returning a Bean , and SAXBuilder finds the error when 
>Digester not.
>
>This is what I had
>        SAXBuilder builder = new SAXBuilder(SAXPARSER, true);
>        builder.setFeature(WITHSCHEMA, true);
>        builder.setProperty(SCHEMALOCATION, xsdFile);
>        return builder.build(reader);
>And now I have an implementation of your suggestion.
>
>I've tryed all the setFeature and setProperty combinations I could 
>imagine with the same result: NO ERROR, NO VALIDATION
>
>Reidar Hörning wrote:
>
>  
>
>>Hi,
>>
>>did you test your xml data against the xsd file with any other tool? I 
>>guess the problem occurs here.
>>
>>Regards
>>Reidar
>>
>>-----Ursprüngliche Nachricht-----
>>Von: José Antonio Pérez Testa [mailto:japtesta@indra.es]
>>Gesendet: Montag, 31. Mai 2004 16:05
>>An: Jakarta Commons Users List
>>Betreff: Re: [Digester] using Schema Validation
>>
>>
>>Hello Reidar,
>>I've done as you suggest and I'm getting the parsing doing well, but no
>>validation against the xsd schema.
>>Xerces complaints when I rename the xsd file, so it  is reading it. But
>>if I put an element in the xml that is not declared in the xsd, 
>>xerces silently ignores it!!
>>
>>
>>Reidar Hörning wrote:
>>
>> 
>>
>>    
>>
>>>Hello Testa,
>>>
>>>as Simon and Trent said schema validation could work this way:
>>>
>>>1. download the Xerces v2 parser and put xercesImpl.jar into the
>>>Classpath 2. configure the parser (example)
>>>
>>>static final String JAXP_SCHEMA_LANGUAGE =
>>>"http://java.sun.com/xml/jaxp/properties/schemaLanguage";
>>>static final String W3C_XML_SCHEMA =
>>>"http://www.w3.org/2001/XMLSchema";
>>>static final String JAXP_SCHEMA_SOURCE =
>>>"http://java.sun.com/xml/jaxp/properties/schemaSource";
>>>
>>>SAXParserFactory factory =
>>>SAXParserFactory.newInstance();
>>>factory.setValidating(true);
>>>
>>>SAXParser parser = factory.newSAXParser();
>>>parser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA); 
>>>parser.setProperty(JAXP_SCHEMA_SOURCE, new File("Your xsd"));
>>>
>>>3. create digester
>>>
>>>Digester d = new Digester();
>>>
>>>4. configure digester at your needs
>>>
>>>5. parse and digest
>>>parser.parse(new FileInputStream(new File("Your xml")), d);
>>>
>>>Regards
>>>Reidar
>>>
>>>-----Ursprüngliche Nachricht-----
>>>Von: José Antonio Pérez Testa [mailto:japtesta@indra.es]
>>>Gesendet: Montag, 31. Mai 2004 13:50
>>>An: Jakarta Commons Users List
>>>Betreff: [Digester] using Schema Validation
>>>
>>>
>>>Hi Thyr,
>>>Could you explain me the changes you made.
>>>I'm trying to configure Digester to do schema validation with xerces
>>>and
>>>
>>>java 1.4
>>>
>>>TIA,
>>>Testa
>>>
>>>---------------------------------------------------------------------
>>>
>>>Hello,
>>>
>>>and much thanks to all for your fast and convenient help. After some 
>>>trouble with changing the underlying parser and refactoring the code, 
>>>schema validation finally works fine.
>>>
>>>Kind Regards
>>>Reidar
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>>>For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>>
>>>
>>>
>>>   
>>>
>>>      
>>>
>>-----------------------------------------------------------------------
>>-
>>-------------------------------------------
>>Este correo electrónico y, en su caso, cualquier fichero anexo al
>>    
>>
>mismo,
>  
>
>>contiene información de carácter confidencial exclusivamente dirigida a
>>su destinatario o destinatarios. Queda prohibida su divulgación, copia
>>    
>>
>o
>  
>
>>distribución a terceros sin la previa autorización escrita de Indra. En
>>el caso de haber recibido este correo electrónico por error, se ruega
>>notificar inmediatamente esta circunstancia mediante reenvío a la
>>dirección electrónica del remitente.
>>
>>The information in this e-mail and in any attachments is confidential 
>>and solely for the attention and use of the named addressee(s). You are
>>    
>>
>
>  
>
>>hereby notified that any dissemination, distribution or copy of this 
>>communication is prohibited without the prior written consent of Indra.
>>    
>>
>
>  
>
>>If you have received this communication in error, please, notify the 
>>sender by reply e-mail
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>
>> 
>>
>>    
>>
>------------------------------------------------------------------------
>-------------------------------------------
>Este correo electrónico y, en su caso, cualquier fichero anexo al mismo,
>contiene información de carácter confidencial exclusivamente dirigida a
>su destinatario o destinatarios. Queda prohibida su divulgación, copia o
>distribución a terceros sin la previa autorización escrita de Indra. En
>el caso de haber recibido este correo electrónico por error, se ruega
>notificar inmediatamente esta circunstancia mediante reenvío a la
>dirección electrónica del remitente.
>
>The information in this e-mail and in any attachments is confidential
>and solely for the attention and use of the named addressee(s). You are
>hereby notified that any dissemination, distribution or copy of this
>communication is prohibited without the prior written consent of Indra.
>If you have received this communication in error, please, notify the
>sender by reply e-mail
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>  
>
-------------------------------------------------------------------------------------------------------------------
Este correo electrónico y, en su caso, cualquier fichero anexo al mismo, contiene información de carácter confidencial exclusivamente dirigida a su destinatario o destinatarios. Queda prohibida su divulgación, copia o distribución a terceros sin la previa autorización escrita de Indra. En el caso de haber recibido este correo electrónico por error, se ruega notificar inmediatamente esta circunstancia mediante reenvío a la dirección electrónica del remitente.

The information in this e-mail and in any attachments is confidential and solely for the attention and use of the named addressee(s). You are hereby notified that any dissemination, distribution or copy of this communication is prohibited without the prior written consent of Indra. If you have received this communication in error, please, notify the sender by reply e-mail

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org