Frage

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

War es hilfreich?

Lösung

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

Andere Tipps

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);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top