Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamic namespaces for XmlElement with JAXB
    primarykey
    data
    text
    <p>I use JAXB marshaller to convert Java classes to XML MRSS files. It looks something like that:</p> <pre><code>public class RssBuilder { public void saveToFile( RSS rss, String fileName ) { JAXBContext jaxbContext = JAXBContext.newInstance( RSS.class ); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, true ); NamespacePrefixMapper mapper = namespaceMapper; marshaller.setProperty( "com.sun.xml.bind.namespacePrefixMapper", mapper ); marshaller.setProperty( Marshaller.JAXB_FRAGMENT, true ); fos = new FileOutputStream( fileName ); marshaller.marshal( rss, fos ); } } @XmlRootElement public class RSS { @XmlElement( name = "channel" ) public List&lt;RssChannel&gt; getChannels() {return channels;} } public class RssChannel { @XmlElement( name = "item" ) private List&lt;RssItem&gt; items; public void setItems( List&lt;RssItem&gt; items ) { this.items = items; } public void addItem( RssItem item ) { this.items.add( item ); } .... } public class RssItem { @XmlElement (name = "description", namespace=RSS.YAHOO_XMLNS) private MediaTitle mediaDescription; @XmlElement (name ="origReleaseDate", namespace=RSS.BING_XMLNS) private String origReleaseDate; .... } </code></pre> <p>There are two MRSS formats by YAHOO and by BING. BING MRSS is almosts similar and just adding some additional elements to YAHOO scheme, so I use two namespaces in elements annotations. The problem that in such way YAHOO MRSS files are also contain xmnls attribute for BING schema although there is no 'bing' elements. I can solve it creating separate RSS root element classes, but it will cause creating separate classes for channel and item elements too.</p> <p>Is there simplier way to solve this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload