2

I would like to know how to bind an XML tag in a certain namespace to some implementation in Java e.g. the way Mule does with the tags defined in it's various XSD files. Is it related/done with JAXB or is that just for mapping Java beans to XML?

Regards Ola

2 Answers 2

1

Check out my article on JAXB and namespaces:

With JAXB you can choose the granularity at which namespace information is provided:

  • At the package level using @XmlSchema
  • At the type level using @XmlType
  • At the field/property level using @XmlElement and @XmlAttribute
Sign up to request clarification or add additional context in comments.

Comments

0

I dont fully understad your question. Are you asking about unmarshalling ?

If so try use sth like below:

JAXBContext ctx = JAXBContext.newInstance("some.package");
Unmarshaller u = ctx.createUnmarshaller();
XMLInputFactory inFac = XMLInputFactory.newFactory();
XMLStreamReader reader = inFac.createXMLStreamReader(this.getClass().
                              getResourceAsStream("inputFile.xml"));
JAXBElement<Mule> freestyleElement = u.unmarshal(reader,Mule.class);

2 Comments

Thanks for the answers and suggestions but it's more about binding functionality to a tag/element rather than marshaling data back and forth. Taking Mule as an example there are a set of tags for different transformations, e.g. <xslt-transformation .../> which binds to a Java class implementing a common interface AbstractTransformer and of course the actual XSLT transformation code. What I don't understand is how the tag is bound to the actual Java implementation.
To clarify a bit more, there is a standard transformer in Mule which have the tag: <object-to-string-transformer name="ToString"/> that is implemented in a class ObjectToStringTransformer. The core of my question is, how is the tag bound to the implementing class? I suspect that the XSD is involved somehow since without refereing to the relevant XSD in the document the tag is undefined but I don't know. There is a lot of articles how to marshall/unmarshall data between Java and XML but that's for data. I have not yet found anything about binding tag to an implementation as desc. above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.