users@jaxb.java.net

specifying no namespace + prefix when unmarshalling XML docs

From: Martyn Taylor <markyblueuk_at_gmail.com>
Date: Fri, 23 Jul 2010 14:47:12 +0100

Hi ppl,

I am having problems using JAXB to unmarshal XML, that does not contain a
reference (with element prefixes) to its schema namespace. I am wondering
if it is possible to modify a setting to tell JAXB that it does not need the
reference to the original namespace when unmarshalling the XML, or whether I
have to add in the namespace and prefix to the document before
unmarshalling.

Your help would be much appriciated

Thanks

Martyn

Example shown below.

Schema ------------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="http://www.example.org/example.xsd"
           xmlns="http://www.example.org/example.xsd">

  <xs:element name="list-object">
    <xs:complexType>
      <xs:sequence maxOccurs="unbounded">
        <xs:element ref="object"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

    <xs:element name="object">
    <xs:complexType>
        <xs:all>
          <xs:element ref="name"/>
          <xs:element ref="description"/>
      </xs:all>
      <xs:attribute ref="id"/>
    </xs:complexType>
  </xs:element>

</xs:schema>

XML Document ---------------------------------

<list-object>
  <object id="1">
    <name>obj1</name>
    <description>object1</description>
  </object>
  <object id="2">
    <name>obj2</name>
    <description>object2</description>
  </object>
</list-object>