Hi Geoffrey,
Geoffrey Fairchild wrote:
> I'm looking over some of what you said. I'm trying to meet a deadline, so
> right now, I'd just like to get the XSD working with the mapping. However,
> I do plan on looking into the XML code generator next week.
>
> I've changed a few things around, but I'm still having issues. For some
> reason, http://www.castor.org/how-to-enable-xml-validation.html just isn't
> clicking.
>
> *castor.xml*:
>
> <?xml version="1.0"?>
> <!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Mapping DTD Version 1.0//EN"
> "http://castor.org/mapping.dtd">
>
> <mapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation="db-config-1.0.xsd">
>
Just repeating myself here: ths is actually invalid. This should read:
<?xml version="1.0"?>
<!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Mapping DTD Version 1.0//EN"
"http://castor.org/mapping.dtd">
<mapping>
That should get you going again.
Werner
> *db-config-1.0.xsd*:
>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
>
> *db-config-sample.xml*:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <dataSource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation="db-config-1.0.xsd">
>
> This is the error I get when I try to unmarshal:
>
> java.lang.RuntimeException: org.exolab.castor.mapping.MappingException:
> Nested error: org.exolab.castor.xml.MarshalException: Attribute "xmlns:xsi"
> must be declared for element type "mapping".{File: [not available]; line: 6;
> column: 52}
>
> Can you tell me what I'm doing wrong here?
>
> Thanks for your patience.
>
> On Wed, Jul 16, 2008 at 12:40 PM, Geoffrey Fairchild <
> [EMAIL PROTECTED]> wrote:
>
>> I'll look into the XML code generator. I didn't know what that was and
>> didn't see that it existed, and that may very well do what I want it to do.
>>
>>
>> On Wed, Jul 16, 2008 at 12:15 PM, Werner Guttmann <[EMAIL PROTECTED]>
>> wrote:
>>
>>> Geoffrey,
>>>
>>> Geoffrey Fairchild wrote:
>>>> Hm, maybe I'm misunderstanding the purpose of the mapping file. I
>>> simply
>>>> want to map from an XML file containing data into a Java object
>>>> representation of that data. The Castor mapping XML file seems like the
>>>> most logical way to do this without having to write a Java XML parser.
>>> Yes, it is most commonly used way of XML data binding when you only have
>>> Java classes, but no XML schema.
>>>> The
>>>> XSD merely provides requirements on how the XML file should be formed.
>>> SUre. But with Castor XML, when you have an XML schema, there's a second
>>> option to about XML data binding, i.e. mapping between XML and Java: the
>>> XML code generator. You basically use the code generator to create Java
>>> classes from an XML schema that automatically correspond to the XML
>>> schema defined. In addition to these domain classes, the code generator
>>> will generate a second set of Java classes, i.e. the descriptor classes.
>>> More further down.
>>>
>>>> I simply followed the guide at
>>>> http://www.castor.org/how-to-enable-xml-validation.html to get my XML
>>> file
>>>> validated against the XSD, but I'm having the issues I previously
>>> mentioned.
>>> Okay, addressing just this question, have you seen my inline comment re:
>>> the invalid use of the 'schemaLoaction' attribute in the mapping file ? >
>>>> What are you talking about when you mention "internal descriptor
>>> classes"?
>>> As explained above, when using the code generator to generate Java
>>> classes from an XML schema, the code generator will generate a second
>>> set of classes which we call 'descriptor classes'. There descriptor
>>> classes define the XML data binding between the Java classes generated
>>> and the XML contract defined in the XML schema. In other words, there is
>>> no need to define a mapping file any more.
>>>
>>> Actually, when you use a mapping file, on startup Castor XML converts
>>> the mapping definitions to (internally use) descriptors.
>>>
>>>> I looked over your website, and it primarily talks about the mapping
>>> file,
>>>> so I'm a little confused. I don't see any mention of "internal
>>> descriptor
>>>> classes."
>>> No, true. But in the left sided menu bar, you'll find a section 'XML
>>> code generator', incl. documentation about integration with build tools
>>> such as Ant, Maven, the binding file, etc.
>>>
>>>> Thanks for your help.
>>>>
>>>> Geoff
>>>>
>>>> On Wed, Jul 16, 2008 at 4:40 AM, Werner Guttmann <
>>> [EMAIL PROTECTED]>
>>>> wrote:
>>>>
>>>>> Geoffrey,
>>>>>
>>>>> why do you want to be using a mapping file to map your Java classes to
>>>>> XML when you have an XML schema available and as such could be in a
>>>>> position where you generate Java classes (and internal descriptor
>>>>> classes) from the XML schema, and as such avoid having to write a
>>>>> mapping file.
>>>>>
>>>>> Geoffrey Fairchild wrote:
>>>>>> First of all, if you have a Something Awful account, you can read a
>>> more
>>>>>> formatted version of this here:
>>>>>> http://forums.somethingawful.com/showthread.php?threadid=2902508
>>>>>>
>>>>>>
>>>>>>
>>>>>> I'll go ahead and rewrite this if you don't have an account.
>>>>>>
>>>>>>
>>>>>>
>>>>>> I've been messing with this most of the afternoon, and I just can't
>>>>> figure
>>>>>> it out.
>>>>>>
>>>>>>
>>>>>>
>>>>>> Basically, I've got an XML file I've got to parse. I need to put the
>>>>> data
>>>>>> into a few Java objects, and Castor is a really easy way to do it.
>>>>> Castor's
>>>>>> working, and it's putting the data in the container properly. The
>>>>> problem
>>>>>> is that I have an XSD schema file defined to validate the XML file,
>>> but
>>>>> I'm
>>>>>> having issues getting Castor to validate it. The XSD is necessary
>>>>> because I
>>>>>> can type complete garbage into the XML file, and Castor reports
>>> success
>>>>> even
>>>>>> though it's totally invalid XML.
>>>>> That's an odd statement. If it's not valid XML, Castor will report
>>>>> exceptions.
>>>>>
>>>>>> I want to prevent this from happening.
>>>>>>
>>>>>>
>>>>>>
>>>>>> I'll get to it. Here're the pertinent lines from *castor.xml*, the
>>> file
>>>>>> that Castor uses to map the XML elements/attributes to the Java
>>> objects:
>>>>>>
>>>>>>
>>>>>> <?xml version="1.0"?>
>>>>>>
>>>>>> <!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Mapping DTD Version
>>> 1.0//EN"
>>>>>> "http://castor.org/mapping.dtd">
>>>>>>
>>>>>>
>>>>>>
>>>>>> <mapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>>>>>
>>>>>> xmlns="http://centurylogix.com/dbconfig"
>>>>>>
>>>>>> xsi:schemaLocation="
>>>>> http://centurylogix.com/dbconfigdb-config-1.0.xsd">
>>>>>>
>>>>>> <class
>>>>>> name="com.centurylogix.graph.hybrid.io.containers.DataSourceInfo">
>>>>>>
>>>>>> <map-to xml="dataSource" ns-uri="
>>>>>> http://centurylogix.com/dbconfig" />
>>>>> Why on earth are you referencing the XML schema file from your mapping
>>>>> file ? That does not make sense at all. If you want Castor to validate
>>>>> your XML document instance against an XML schema, please refer to the
>>>>> XML schema from the XML document instance 8and nowhere else).
>>>>>
>>>>>> If you need more than that, I can post it, but those should be the
>>> only
>>>>>> relevant lines.
>>>>>>
>>>>>>
>>>>>>
>>>>>> Here're the first few lines from *db-config-1.0.xsd* which is
>>> obviously
>>>>> the
>>>>>> schema file used to verify the XML file:
>>>>>>
>>>>>>
>>>>>>
>>>>>> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
>>>>>>
>>>>>> targetNamespace="http://centurylogix.com/dbconfig"
>>>>>>
>>>>>> xmlns="http://centurylogix.com/dbconfig"
>>>>>>
>>>>>> elementFormDefault="qualified">
>>>>>>
>>>>>>
>>>>>>
>>>>>> And here're the first few lines from *db-config-sample.xml*, a sample
>>> XML
>>>>>> file that Castor reads in and puts into the correct Java objects:
>>>>>>
>>>>>>
>>>>>>
>>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>>>
>>>>>> <dataSource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>>>>>
>>>>>> xsi:schemaLocation="
>>>>> http://centurylogix.com/dbconfigdb-config-1.0.xsd">
>>>>>>
>>>>>> I do have a *castor.properties* file defined with the following
>>> contents,
>>>>>> per http://www.castor.org/how-to-enable-xml-validation.html:
>>>>>>
>>>>>>
>>>>>>
>>>>>> org.exolab.castor.indent=true
>>>>>>
>>>>>> org.exolab.castor.parser.namespaces=true
>>>>>>
>>>>>> org.exolab.castor.sax.features=
>>> http://xml.org/sax/features/validation,\<http://xml.org/sax/features/validation,%5C>
>>> <http://xml.org/sax/features/validation,%5C>
>>>>>>
>>>>>> http://apache.org/xml/features/validation/schema,\<http://apache.org/xml/features/validation/schema,%5C>
>>> <http://apache.org/xml/features/validation/schema,%5C>
>>>>>>
>>>>> http://apache.org/xml/features/validation/schema-full-checking
>>>>>>
>>>>>> When I try to unmarshal the data, this is the error I get:
>>>>>>
>>>>>>
>>>>>>
>>>>>> java.lang.RuntimeException:
>>> org.exolab.castor.mapping.MappingException:
>>>>>> Nested error: org.exolab.castor.xml.MarshalException: Attribute
>>>>> "xmlns:xsi"
>>>>>> must be declared for element type "mapping".{File: [not available];
>>> line:
>>>>> 7;
>>>>>> column: 74}
>>>>>>
>>>>>>
>>>>>>
>>>>>> I don't quite understand this error. "xmlns:xsi" is clearly defined
>>> in
>>>>> the
>>>>>> mapping element in castor.xml. Do any of you know what I'm doing
>>> wrong?
>>>>>> Any ideas at all? I think this is one those things that's probably
>>>>> simple
>>>>>> to fix, but I've just been staring at it too long, and I'm not seeing
>>> the
>>>>>> solution. Thanks!
>>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> 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