Okay, thanks for taking time to explain this in detail. It is now far
clearer to me as to what your environment is. Let me have a look at this
in detail tomorrow.

Werner

Mike Ferraro wrote:
> Quoting Werner Guttmann <[EMAIL PROTECTED]>:
>> Why are you actually creating a mapping file in this case, when you could be
>> using Castor's XML code generator to generate Java classes (and descriptor
>> classes that are an internal representation of the mapping file you are
>> providing) out of the box ?
> 
> I have a pre-existing persistence library that was built to access our 
> database.
>  The persistence library already has its own "bean" objects for holding data. 
>  I
> am attempting to build an import application to import XML data files from
> another group.  The other group already has an XSD defined for a file format
> that is already in use for other data feeds that they perform.
> 
> My choices were to either (a) create a whole new set of objects for this XSD
> using Castor and then write custom code to map all of those new objects to my
> existing persistence library objects or (b) write a mapping file to map the
> existing XSD to the existing objects.  (a) totally defeats the purpose of the
> whole "buy vs. build" concept and if I had to write my own code I could
> probably get better performance and have more control if I parsed the XML
> myself and translated to my objects directly.  So, I chose to go with (b) in
> hopes that I would have to write less code and maintaining changes on either
> side would be simpler because I would only have to change a mapping file.  
> And,
> since Castor was the only tool that I could find that allowed for a mapping
> between pre-existing XSD and Java objects, I chose to go with Castor.
> 
> Since my email yesterday I have worked through some other mapping file/code
> combinations and come out with a few other results.  All of them consist of
> some sort of prefix being prepended to the XML attributes and all of them
> result in an invalid XML document.  Because of this, I have resorted to 
> getting
> the XML as close as I can to what I expect through Castor, turning off 
> Castor's
> marshalling validation (which didn't seem work anyway, which I guess is a
> different issue), and then manually reformatting the XML so that it is valid.
> 
> So, does anyone know the correct way to get my attributes marshalled without a
> namespace prefix and my elements marshalled with my namespace prefix?  (Along
> with the correct namespace declarations in my XML.)  I'd be happy to include
> the XSD and mapping file that I'm working with if that helps.
> 
> Thank you,
> Mike
> 
> 
> 
>>> -----Ursprüngliche Nachricht-----
>>> Von: Mike Ferraro [mailto:[EMAIL PROTECTED]
>>> Gesendet: Mittwoch, 07. März 2007 19:07
>>> An: [email protected]
>>> Betreff: [castor-user] [XML] Problem with marshalling and namespace
>>> prefixes
>>>
>>> Hello,
>>>
>>> I have created a mapping file to map an existing XSD to existing Java
>>> classes.
>>> Unmarshalling the XML seems to run fine, but I am having trouble getting
>>> valid
>>> XML when marshalling the objects.  I am trying to marshal an object and
>>> create
>>> XML with namespace prefixes for the elements and no prefixes for the
>>> attributes, as defined by the XSD I'm working with, like this:
>>>
>>> <pre:rootElement
>>>     xmlns="http://my.name.space";
>>>     xmlns:pre="http://my.name.space";
>>>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>>>     xsi:schemaLocation="http://my.name.space http://my.xsd.location";
>>>     attribute1="valueA"
>>>     attribute2="valueB">
>>>   <pre:element1 attribute1="valueA"
>>>                 attribute2="valueB">elementValue</pre:element1>
>>> </pre:rootElement>
>>>
>>> In my mapping file, the attributes are mapped as "attribute1" and elements
>>> are
>>> mapped as "pre:element1".  I have tried several different variations in my
>>> marshalling code, but the three results that I keep getting are (all of
>>> which
>>> are invalid according to the XSD):
>>>
>>> 1. Elements and attribute both have my namespace prefix.
>>> 2. Elements and attribute both do not have any prefixes.
>>> 3. Elements have my namespace prefix and attributes are given an "ns1"
>>> prefix
>>> for a Castor namespace.
>>>
>>> I modeled my mapping file after the example in the XML validation section
>>> in the
>>> Castor documentation and the namespaces look like this:
>>>
>>> <mapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>>>          xmlns="http://castor.exolab.org/";
>>>          xmlns:pre="http://my.name.space";
>>>          xsi:schemaLocation="http://castor.exolab.org/ mapping.xsd">
>>>
>>> I have been trying different variations on the above header and of this
>>> marshalling code, with no luck:
>>>
>>> marshaller.setNamespaceMapping("", "http://my.name.space";);
>>> marshaller.setNamespaceMapping("pre", "http://my.name.space";);
>>> marshaller.setSchemaLocation("http://my.name.space
>>> http://my.xsd.location";);
>>> marshaller.marshal(valueObject);
>>>
>>> Does anyone know the correct way to get my attributes marshalled without a
>>> namespace prefix and my elements marshalled with my namespace prefix?
>>> (Along
>>> with the correct namespace declarations in my XML.)
>>>
>>> Thank you,
>>> Mike
>>>
>>> ---------------------------------------------------------------------
>>> 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

Reply via email to