Jean-Baptiste,
BINET JEAN-BAPTISTE wrote:
> Thanks to you the problem is now solved. Many thanks :)
>
> But I still have another question since now there is the following error :
> org.exolab.castor.xml.MarshalException: cvc-elt.1: Cannot find the
> declaration of element 'jb_xs:REQUEST'.{File: [not available]; line: 2;
> column: 263}
>
> How can I precise the exact directory where my file XSD is available, because
> it seems that the
> parser is not able to find it ?
There's a few options here.
a) Make sure the XML schema is in the same directory as the XML document
you are about to unmarshal. Problemm is, that's a valid strategy for
e.g. test cases only.
b) Supply a custom org.sax.EntityResolver to Castor's Unmarshaller. Have
a look at
http://castor.org/how-to-fetch-dtds-and-schemas-from-jars.html
and let me know whether you have any further question.
Regards
Werner
PS Just re-reading what I have said above, I wonder why I have to refer
folks that frequently to HOW-TOs. My assumption would be that users woul
dread FAQs and/or HOW-TOs before asking questions (again and again). Is
that assumption actually wrong ?
> I tried to do :
> Unmarshaller unmar = new Unmarshaller(mapping);
> unmar.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation",
> "http://www.jb.com/jb_xs
> file:/C:/Sonic/Workbench7.6/workspace/MPv3_EnrichTransform/build/classes/request.xsd");
> Request request = (Request) unmar.unmarshal(new StringReader(xml));
>
> But it doesn't work.
>
> Regards,
>
> JB
>
> -----Message d'origine-----
> De : Werner Guttmann [mailto:[EMAIL PROTECTED]
> Envoyé : mercredi 23 juillet 2008 13:52
> À : [email protected]
> Objet : Re: [castor-user] XSD schema validation
>
> I guess I know what the problem is. in your castor.properties file, you have
> specified that you want the (underlying) XML parser to validate your
> documents against the XML schemas provided.
>
> This is both valid for your XML document instance as well as the mapping
> file, as both of them will be processed by an XML parser when Castor tries to
> unmarshal those documents.
>
> In other words, when ypu have got those properties set, you need to have a
> schemaLocation attribute defined, as that#s what the XML parser seems to
> expect.
>
> You now have to fix your schemaLocation attribute value in mapping.xml to get
> things working. Can you please use
>
> xsi:schemaLocation="http://castor.exolab.org/
> http://castor.exolab.org/mapping.xsd"
>
> and see whether this resolves the issue.
>
> Werner
>
> BINET JEAN-BAPTISTE wrote:
>> I tried to remove the schemaLocation line my mapping file and now I have the
>> following error :
>>
>> org.exolab.castor.mapping.MappingException: Nested error:
>> org.exolab.castor.xml.MarshalException: cvc-elt.1: Cannot find the
>> declaration of element 'mapping'.{File:
>> file:///C:/Sonic/Workbench7.6/workspace/MPv3_EnrichTransform/castorMap
>> ping.xml; line: 5; column: 97}
>>
>> Does someone have another example of XSD validation that the one provided on
>> castor web site ?
>> Thanks.
>>
>> Regards,
>>
>> JB
>>
>> -----Message d'origine-----
>> De : Werner Guttmann [mailto:[EMAIL PROTECTED] Envoyé :
>> mercredi 23 juillet 2008 12:09 À : [email protected] Objet :
>> Re: [castor-user] XSD schema validation
>>
>> Hello,
>>
>> how about dropping the schemaLocation attribute (for the time being) from
>> your mapping file, and check whether this resolves the issue ?
>>
>> Werner
>>
>> BINET JEAN-BAPTISTE wrote:
>>> Hello,
>>>
>>> First, thanks for your help.
>>>
>>> a) I tried without the space and the error is now :
>>>
>>> org.exolab.castor.mapping.MappingException: Nested error:
>>> org.exolab.castor.xml.MarshalException: SchemaLocation:
>>> schemaLocation value = 'http://castor.exolab.org/mapping.xsd' must
>>> have even number of URI's.{File:
>>> file:///C:/Sonic/Workbench7.6/workspace/MPv3_EnrichTransform/castorMa
>>> p
>>> ping.xml; line: 6; column: 68}
>>>
>>> b) I use a mapping file because my business classes already exist so I
>>> don't want new generated classes.
>>>
>>> Regards,
>>>
>>> JB
>>>
>>> -----Message d'origine-----
>>> De : Werner Guttmann [mailto:[EMAIL PROTECTED] Envoyé :
>>> mercredi 23 juillet 2008 11:34 À : [email protected] Objet :
>>> Re: [castor-user] XSD schema validation
>>>
>>> Okay, a few observations....
>>>
>>> a) That xsi:schemaLocation attribute mentioned below should read
>>>
>>> xsi:schemaLocation="http://castor.exolab.org/mapping.xsd"
>>>
>>> where you do not have any spaces in the attribute value.
>>>
>>> b) Why are you using a mapping file when you could generate Java code from
>>> your XML schema which includes descriptor classes that have validators set
>>> as defined by your XML schema constraints.
>>>
>>> Regards
>>> Werner
>>>
>>> BINET JEAN-BAPTISTE wrote:
>>>> Hello,
>>>>
>>>> I am new to Castor and I am really blocked on XSD validation. I have
>>>> an XML and an XSD to validate this XML.
>>>> I succeeded in writting a mapping file to converter my XML into my
>>>> business objects but now I would like to add the validation of the
>>>> XML. I looked at the example on the web site but I am sorry, I don't
>>>> understand.
>>>> Can you tell me why there is
>>>> xsi:schemaLocation="http://castor.exolab.org/ mapping.xsd"
>>>> in the mapping file ?
>>>>
>>>> I have the following XML :
>>>> <jb_xs:REQUEST xmlns:jb_xs="http://www.jb.com/jb_xs"
>>>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>>> xsi:schemaLocation="http://www.jb.com/jb_xs request.xsd">
>>>> <jb_xs:RequestIdentificatio>
>>>> <jb_xs:source>OrderManagement</jb_xs:source>
>>>> <jb_xs:request_id>2</jb_xs:request_id>
>>>> ...
>>>>
>>>>
>>>> And the following XSD :
>>>> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
>>>> elementFormDefault="qualified" targetNamespace="http://www.jb.com/jb_xs"
>>>> xmlns:jb_xs="http://www.jb.com/jb_xs">
>>>> <xs:element name="REQUEST">
>>>> <xs:complexType>
>>>> ...
>>>>
>>>> And the following castor.properties :
>>>> org.exolab.castor.parser.namespaces=true
>>>> org.exolab.castor.sax.features=http://xml.org/sax/features/validation,\
>>>> http://apache.org/xml/features/validation/schema,\
>>>> http://apache.org/xml/features/validation/schema-full-checking
>>>>
>>>> So I tried with the following castorMapping.xml file according to
>>>> your example :
>>>> <mapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>>> xmlns="http://castor.exolab.org/"
>>>> xmlns:jb_xs="http://www.jb.om/jb_xs"
>>>> xsi:schemaLocation="http://castor.exolab.org/ mapping.xsd">
>>>> ...
>>>>
>>>> But when I run my Java code, I have the following error :
>>>> org.exolab.castor.mapping.MappingException: Nested error:
>>>> org.exolab.castor.xml.MarshalException: schema_reference.4: Failed
>>>> to read schema document 'mapping.xsd', because 1) could not find the
>>>> document; 2) the document could not be read; 3) the root element of
>>>> the document is not <xsd:schema>.{File:
>>>> file:///C:/Sonic/Workbench7.6/workspace/MPv3_EnrichTransform/castorM
>>>> a
>>>> p
>>>> pi
>>>> ng.xml; line: 6; column: 69}
>>>>
>>>> Can anyone help me please because I am really lost.
>>>>
>>>> Thanks in advance.
>>>>
>>>> Regards.
>>>>
>>>> JB
>>>>
>>>>
>>>>
>>>>
>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe from this list, please visit:
>>>
>>> http://xircles.codehaus.org/manage_email
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe from this list, please visit:
>>>
>>> http://xircles.codehaus.org/manage_email
>>>
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>> http://xircles.codehaus.org/manage_email
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>> http://xircles.codehaus.org/manage_email
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
> http://xircles.codehaus.org/manage_email
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
> http://xircles.codehaus.org/manage_email
>
>
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email