What does your JUnit test case look like ? As there should NOT be any
difference on whether you use Castor from a Java application or a JUnit
test.

Kind Regards
Werner

On 15.03.2011 06:46, rag007 wrote:
> 
> Thanks for your reply. I am facing one more problem here. 
> 
> Scenario 1:
> I have one sample xml, for example test.xml. Using Unmarshalling concept, i
> filled the java objects based on given sample xml. Again I convert into
> another xml like test2.xml through marshalling. Its working fine from
> calling main method. If i call in some other method (Like Junit). Its not
> working for me. Please find the following code.
> 
>                     FileReader in = new FileReader("test.xml");
>             Unmarshaller h_unmarshaller = new 
> Unmarshaller(RootDocument.class);
>             h_unmarshaller.setValidation(false);
>             RootDocument rdc = (RootDocument) h_unmarshaller.unmarshal(in);
>             System.out.println("DONE Unmarshalling\n\n");
>               
>             File file = new File("test2.xml");
>             Writer writer = new FileWriter(file);
>             Marshaller marsh = new Marshaller(writer);
>             marsh.setNamespaceMapping("scp",
> "http://www.demo.com/ICT/XML/student/ABD";);
>             marsh.setNamespaceMapping("gen",
> "http://www.demo.com/ICT/XML/student/XYZ";);
>             marsh.marshal(rdc);
>             System.out.println("DONE Marshalling");
> 
>>From main method its working. I am getting like this 
> 
> (This is sample only.But format is correct.)
> <abc:RootDocument xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
>  xmlns:xyz="http://www.demo.com/ICT/XML/Student/General"; 
> xmlns:abc="http://www.demo.com/ICT/XML/Student/ABC";> 
>  <xyz:header> 
>  <xyz:school> 
>  <xyz:schoolid>123</gen:schoolid> 
>   <xyz:schoolname>ABCDD</gen:schoolname> 
>    </xyz:school> 
>  </xyz:header> 
> <abc:footer> 
>    <abc:result abc:studNr="999"> 
>     <abc:studType>GHJJ</scp:studType> 
>    </abc:result> 
>  </abc:footer> 
>  </abc:RootDocument> 
> 
> 
> 
> 
> By using junit, i am getting like this
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <root-document valid="true" valid="true"
>       xmlns:abd="http://www.demo.com/ICT/XML/student/ABD";
>       xmlns:xyz="http://www.demo.com/ICT/XML/student/XYZ";>
>       <student valid="true" valid="true">
>                           <marks valid="true" valid="true" />
>               <subject valid="true" valid="true">
>                       <eng></eng>
>                       <tam>GGG</tam>
>               </subject>
>               </student>
> </root-document>
> 
> 
> Scenario 2:
> 
> In the same way, I have one xsd file. Through castor, i generated java
> objects and filled those objects (via code) based on given sample xml. After
> that i used like this
> 
>                    File file = new File("test2.xml");
>             Writer writer = new FileWriter(file);
>             Marshaller marsh = new Marshaller(writer);
>             marsh.setNamespaceMapping("scp",
> "http://www.demo.com/ICT/XML/student/ABD";);
>             marsh.setNamespaceMapping("gen",
> "http://www.demo.com/ICT/XML/student/XYZ";);
>             marsh.marshal(rdc);
>             System.out.println("DONE Marshalling");
> 
> But i am getting the same xml
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <root-document valid="true" valid="true"
>       xmlns:abd="http://www.demo.com/ICT/XML/student/ABD";
>       xmlns:xyz="http://www.demo.com/ICT/XML/student/XYZ";>
>       <student valid="true" valid="true">
>                           <marks valid="true" valid="true" />
>               <subject valid="true" valid="true">
>                       <eng></eng>
>                       <tam>GGG</tam>
>               </student>
>               </student>
> </root-document>
> 
> Note :I am using castor 1.3 and jdk1.5.  I didnt use any mapping file. When
> generating java objects from xsd, each file we have one validate method like
> this. It always return true. Is it correct?
>  public boolean isValid(
>     ) {
>         try {
>             validate();
>         } catch (org.exolab.castor.xml.ValidationException vex) {
>             return false;
>         }
>         return true;
>     }
>  public void marshal(
>             final java.io.Writer out)
>     throws org.exolab.castor.xml.MarshalException,
> org.exolab.castor.xml.ValidationException {
>         org.exolab.castor.xml.Marshaller.marshal(this, out);
>     }
>  public static packagename.student unmarshal(
>             final java.io.Reader reader)
>     throws org.exolab.castor.xml.MarshalException,
> org.exolab.castor.xml.ValidationException {
>         return (packagename.student)
> org.exolab.castor.xml.Unmarshaller.unmarshal(packagename.student.class,
> reader);
>     }
> 
> please do needful help. Thanks in advance.
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Werner Guttmann-6 wrote:
>>
>> Hi,
>>
>> On 09.03.2011 18:01, rag007 wrote:
>>>
>>> Thanks for your reply.
>>>
>>> This is the sample xml i need to generate 
>>>
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <abc:RootDocument xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>>> xmlns:xyz="http://www.demo.com/ICT/XML/Student/General"; 
>>> xmlns:abc="http://www.demo.com/ICT/XML/Student/ABC";
>>> xmlns="http://www.demo.com/Student/ABC";
>>> xsi:schemaLocation="http://www.demo.com/ICT/XML/Student/General
>>> sample1.xsd
>>> http://www.demo.com/ICT/XML/Student/ABC sample2.xsd">
>>> <xyz:header>
>>>   <xyz:school>
>>>   <xyz:schoolid>123</gen:schoolid> 
>>>   <xyz:schoolname>ABCDD</gen:schoolname> 
>>>   </xyz:school>
>>> </xyz:header>
>>> <abc:footer>
>>>   <abc:result abc:studNr="999">
>>>     <abc:studType>GHJJ</scp:studType> 
>>>   </abc:result>
>>> </abc:footer>
>>> </abc:RootDocument>
>>>
>>>
>>> But, Through castor i am getting XML like this
>>>
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <RootDocument xmlns="http://www.demo.com/ICT/XML/Student/ABC";>
>>> <ns1:header xmlns:ns1="http://www.demo.com/ICT/XML/Student/General";>
>>> <ns1:school>
>>> <ns1:schoolid>123</ns1:schoolid>
>>> <ns1:schoolname>ABCDD</ns1:schoolname>
>>> </ns1:school>
>>> </ns1:header>
>>> <footer>
>>> <result xmlns:ns2="http://www.demo.com/ICT/XML/Student/ABC";
>>> ns2:studNr="999">
>>> <ns2:studType>GHJJ</ns2:studType>
>>> </result>
>>> </footer>
>>> </RootDocument>
>>>
>>>
>>> Please clarify this. I am little confused. I want to know whether both
>>> xml
>>> is same or not?
>> Technically speaking, namespace prefixes are not really relevant in an
>> XML document instance. But if you really, really need to use a
>> particular namespace prefix, please have a look at the
>>
>> Marshaller.setNamespaceMapping()
>>
>> method, which allows you to assign your own (custom) namepace prefixes
>> to given namespaces.
>>
>> Regards
>> Werner
>>
>>>
>>> How to give custom prefix in the XML element?
>>>
>>> Thanks in Advance.
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> Werner Guttmann-6 wrote:
>>>>
>>>> Hi,
>>>>
>>>> On 09.03.2011 17:12, rag007 wrote:
>>>>>
>>>>> Hi All,
>>>>>
>>>>> I am using castor in myapplication. I am new to this. I have one doubt
>>>>> please clarify as soon as possible.
>>>>>
>>>>> I have one xsd file through that i generated java files. Not an issue.
>>>>> Its
>>>>> ok for me. My question, is it possible to get mapping file along with
>>>>> that?
>>>> Why would you need a mapping file at all when you generate Java sources
>>>> from an XML schema. During code generation, Castor generates Java POJOs
>>>> AND descriptor classes, which are an optimized (internal) representation
>>>> of the XML to object mapping.
>>>>
>>>>> I used gen-mapping command but its not working for me. I am using
>>>>> castor
>>>>> 1.3. Because I need to use custom namespace prefix in my xml. 
>>>> Where's the issue. If your XML schema has correct namespace definitions,
>>>> Castor will use the right namespace URIs/prefixes for your XML.
>>>>>
>>>>> Kindly help me asap.
>>>>>
>>>>> Thanks in advance.
>>>> Kind Regards
>>>> Werner Guttmann
>>>>
>>>> ---------------------------------------------------------------------
>>>> 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