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

有帮助吗?

解决方案

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

其他提示

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);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top