users@jaxb.java.net

Re: Namespace question

From: Kenny MacLeod <kennym_at_kizoom.com>
Date: Mon, 3 Mar 2008 16:51:08 +0000

Are you sure you really need JAXB to use the default namespace? The XML
spec says that it doesn't matter if it uses namespace prefixes or the
default namespace, the two are semantically identical.

I think you can control the prefixes in JAXB, but offhand I don't know how.



svennissel wrote:
> I have some chaos with the namespaces.
>
> My Schema
> _________________________________________
> <?xml version="1.0" encoding="UTF-8"?>
> <schema xmlns="http://www.w3.org/2001/XMLSchema"
> targetNamespace="http://www.test.com/test"
> xmlns:test="http://www.test.com/test">
>
> <complexType name="calibrationfile">
> <sequence minOccurs="1" maxOccurs="1">
> <element name="description" type="string" minOccurs="0"
> maxOccurs="1"></element>
> <element name="products" type="test:products" minOccurs="1"
> maxOccurs="1"></element>
> </sequence>
> <attribute name="revision" type="nonNegativeInteger"
> use="required"></attribute>
> </complexType>
> ....
> _________________________________________
>
> My Root Class in Java
> ________________________________
> @XmlAccessorType(XmlAccessType.FIELD)
> @XmlType(propOrder = { "description", "products" })
> @XmlRootElement(name = "calibrationfile")
> public class Calibrationfile {
> ....
> ______________________________
>
> My "Schema part" at the marshal process
> ________________________
> String schemaPath = "http://www.test.com/test ee_schema.xsd";
> marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, schemaPath);
> SchemaFactory sf =
> SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
> Schema schema = sf.newSchema(schemaFile);
> //marshaller.setSchema(schema);
> ____________________________
>
> Now if i write the XML file, the Namespaces of the are not right.
> "http://www.test.com/test" must be default, but it has the token ns2.
> _________________________
> <calibrationfile xmlns:ns2="http://www.test.com/test"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://www.test.com/test ee_schema.xsd"> ....
> _________________
>
> The right xml file might be:
> ____________________________
> <calibrationfile xmlns="http://www.test.com/test"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://www.test.com/test ee_schema.xsd ">
> ....
> ___________________________________
>
>
> How can I configurate this in JAXB? I think i must add Annotations in the
> package-info.java. But I don't now which.
> --
> View this message in context: http://www.nabble.com/Namespace-question-tp15804885p15804885.html
> Sent from the java.net - jaxb users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>