jaxb

JAXB: How do I annotate classes so that they belong to different namespaces?

Hello! I want to have JAXB-annotated classes which would be marshalled/unmarshalled to different XML namespaces. What I need is something like: <someRootElement xmlns="urn:my:ns1" xmlns:a="urn:my:ns2" xmlns:b="urn:my:ns3"> <someElement/> <a:someElement/> <b:someElement/> </someRootElement> How can it be done? Can it be ...

How to make a deep copy of JAXB object like xmlbean XmlObject.copy()?

I have been tasked with refactoring some components that used xmlbeans to now make use of jaxb. Everything is going great, until I get to a place where the previous author has called the copy() function of one of the XmlObjects. Since all objects in xmlbeans extend XmlObject, we get the magic deep copy function for free. Jaxb does not s...

JAXB List of Choice

I have following schema <complexType name="BookShelf"> <sequence> <element name="newBook" type="string" minOccurs="0" maxOccurs="unbounded"/> <element name="oldBook" type="string" minOccurs="0" maxOccurs="unbounded"/> </sequence> </complexType> XJC generates BookShelf class with two lists, one for newBook and one for...

Prefixing JAXB generated classes

I have this Maven "task" to generate Java classes from an XSD file using JAXB. <!-- XML to Java classes --> <plugin> <groupId>com.sun.tools.xjc.maven2</groupId> <artifactId>maven-jaxb-plugin</artifactId> <executions> <execution> <phase>generate-sources</phase> <goals> <goal>generate</goal> </g...

How do I use a jaxb.index file?

I'm getting a javax.xml.bind.JAXBException: "doesnt contain ObjectFactory.class or jaxb.index" while trying to create a JAXBContext using JAXBContext.newInstance(String contextPath). I'm guessing there's a "usual" way to create and maintain a jaxb.index file? ...

How Do I Clone A JAXB Object

I have some jaxb objects (instantiated from code generated from xsd by jaxb) that I need to clone. The Jaxb class does not appear to provide an interface for doing this easily. I can not hand edit the class and can not extend it - so I need to create a helper/utility method to do this. What is the best approach? ...

Referencing JAXB jars - best practice

My first post, so go easy on me. I'm looking for advice on organising and referencing third party jars for use in my j2ee web application. The jars I need to organise and reference are the JWSDP-2.0 JAXB api jars. I'm using Eclipse and Tomcat 5.5. My web app exchanges XML with a web service, and therefore needs to do some XML marshall...

What's the point of JAXB 2's ObjectFactory classes?

I'm new to using JAXB, and I used JAXB 2.1.3's xjc to generate a set of classes from my XML Schema. In addition to generating a class for each element in my schema, it created an ObjectFactory class. There doesn't seem to be anything stopping me from instantiating the elements directly, e.g. MyElement element = new MyElement(); where...

Xml data in String type

I am connecting to a webservice which has a service deifnition of the following format <main> <header> <data>xyz</data> </header> <test> <![CDATA[<xml><a></a><b></b></xml>]]> </test> </main> How do I use jaxb to create class file for the cdata strcture ...

jaxb marshall complex structure

Hi, I have a structure like this: Hashtable<String, ArrayList<Hashtable<Integer, Integer>>> complexTable And I want to marshall this using JAXB. I suppose I should write an Adapter for this, but I have no idea how this adapter should look like. Can anybody help me with this? ...

How to map already existing java bean in JAXB

Castor framework (xml to java bean binder framework) provides functionality to map my existing java bean to xml. Can I achieve same thing using JAXB ? ...

XSD: ComplexType

Hi, I have a complexType like: <xsd:complexType name="NightlyRate"> <xsd:complexContent> <xsd:extension base="com:Money"> <xsd:attribute name="night" type="com:Number" use="required"/> </xsd:extension> </xsd:complexContent> </xsd:complexType> Now, I want to add a child element to "NightlyRate", whi...

How do i instantiate a JAXBElement<String> object?

I need to create one of these as the interface requires it...can someone please let me know how to create one, as there doesnt seem to be a c'tor defined? ...

How can I have JAXB call a method after it has completed unmarshalling an XML file into an object?

I am using JAXB to unmarshall an XML file into a Java object -- standard stuff. Once JAXB has completed this, I'd like a method to be called on the newly created object. Is there a mechanism to do this? I'd prefer the object, not an external entity, do this to keep construction in one place. Thanks. ...

Xsd:list--> date issue

Hi, I am using JAXB to parse my xml schema(xsd). I have a complexType as follows: <xsd:complexType name="PromotionalInfo"> <xsd:attribute name="promotionName" type="xsd:string" use="required"/> <xsd:attribute name="blackOutDates" type="DateList"/> <xsd:attribute name="amount" type="xsd:float" use="required"/> <xsd:attri...

XML-schema: Equivalent to nullable="true" for attributes?

Hi, I have been having problem with adding type="date" in my schema, as whenever it is null it throws a marshalling error. I found out that for elements we can add an attribute like nullable="true" and get rid of this issue. But, wasn't able to find similar way for attributes. Is there a way to avoid this issue for attributes? Thanks!...

How to annotate a member of type collection in jaxb

I have successfully marshaled the following class @XmlRootElement(name = "Field") private static class MyField { @XmlAttribute(name = "Name") String name; @XmlElement(name = "Size") int size; ....} Now I want to have my container class to hold multiple instances of Field, so I declared a class in the followi...

Unmarshaling xml with html entities using JAXB

I need to load wikipedia revision histories into POJOs, so I'm using JAXB to unmarshall the wikipeida data dump (well, individual pages of it). The problem is that the text nodes occasionally contain entities that are not defined in the wikipedia xml dump. eg: (`&deg;' pleases keep in mind that I do not know the complete set of entiti...

Unmarshalling collections in JaxB

Hi, suppose I have this class: public class A { private HashMap<String, B> map; @XmlElement private void setB(ArrayList<B> col) { ... } private ArrayList<B> getB() { ... } } When trying to unmarshall an xml document to this class using JaxB I notice that instead of calling the setB() method...

How to change XML based on regex matches to text (character data)

I am trying to match the text contents(character data) of an XML file with a series of regexs and then change the XML based on the matches. Example: <text> <para>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </para> </text> I want to match for instance ...