Search code examples
javaattributesmarshallingcastor

How to add Prefix for the attribute while marshling


I like to add prefix for attribute while marshaling using castors.

I would like to get result as like below

<ThesaurusConcept dc:identifier="C268">
    <ScopeNote xml:lang="en">
        <LexicalValue>index heading is Atomic absorption spectroscopy</LexicalValue>
    </ScopeNote>            
</ThesaurusConcept>

but I am getting

<ThesaurusConcept identifier="C621">
<ScopeNote lang="en">
    <LexicalValue>index heading is Atomic absorption spectroscopy</LexicalValue>
    </ScopeNote>  
</ThesaurusConcept>

Solution

  • I got an answer for my question

    we need to add the following in mapping.xml file

    <mapping  xmlns:dc="http://purl.org/dc/elements/1.1/"> 
    
    <bind-xml name="dc:identifier" node="attribute" ></bind-xml>
    

    and also we need to set namespace by using following code.

    Marshaller  casreactmp = new Marshaller(handler);
                casreactmp.setNamespaceMapping("dc", "http://purl.org/dc/elements/1.1/");