users@jaxb.java.net

Re: specifying no namespace + prefix when unmarshalling XML docs

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Fri, 23 Jul 2010 18:48:31 +0200

I think a simple stylesheet would be the easiest way, eg.

<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="element()">
    <xsl:element name="{name(.)}"
namespace="http://www.example.org/example.xsd">
      <xsl:namespace name="">http://www.example.org/example.xsd</xsl:namespace>
      <xsl:copy-of select="@*"/>
      <xsl:apply-templates/>
    </xsl:element>
  </xsl:template>

</xsl:stylesheet>


On 23 July 2010 15:47, Martyn Taylor <markyblueuk_at_gmail.com> wrote:
> 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>
>
>
>