users@jaxb.java.net

Re: specifying no namespace + prefix when unmarshalling XML docs

From: Martyn Taylor <markyblueuk_at_gmail.com>
Date: Sun, 25 Jul 2010 10:40:57 +0100

Thanks for your suggestion,

I was however, wondering if this was possible without modifying the XML. I
was thinking that maybe we could tell the JABX unmarshaller that all
incoming elements will map to a specific namespace whether the namespace and
prefix is present or not.

Again, this may not be possible and your suggestion using a StyleSheet may
be the optimal solution to my problem.

Cheers

Martyn

On 23 July 2010 17:48, Wolfgang Laun <wolfgang.laun_at_gmail.com> wrote:

> 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>
> >
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>