Let me bring another perspective to
this:
XMLSchema forces you to have separate Schema files for each
namespace that you want to cover. So if you want part of your elements to have
no namespace and part of them to have the "metadata" namespace, you need two
Schema files, one without "targetNamespace" and one with "targetNamespace='http://beta.video.cnbc.com/rss/2.0/modules/videoMetadata'"
My
opinion is that the best thing to do would be to just
add "targetNamespace='http://beta.video.cnbc.com/rss/2.0/modules/videoMetadata'" to
the Schema that you already have and then use xmlns=http://beta.video.cnbc.com/rss/2.0/modules/videoMetadata in your instance documents
to put all elements in that namespace; problem solved.
It is
indeed a good idea to run your documents through a validator first to see if
your documents match your expectations, you can do this very easily with
XMLBeans using
scomp.cmd <Schema_file> <XML_file>
which
tends to be more reliable than doing it with XML Spy.
Radu
Looks like your XSD is not correct.
I think you need to make the
elements with <item> like
<xsd:element
name="category" type="xsd:string"/>
<xsd:element name="action" type="xsd:string"/>
etc.
be
like
<xsd:element name="category"
type="metadata:category"/>
<xsd:element
name="action" type="metadata:action"/>
etc.
You can verify your
schema with a validation tool like XMLSpy, to make sure the schema you created
is correct.
I could not quickly verify my suggestion in this case, as the
schema
http://beta.video.cnbc.com/rss/2.0/modules/videoMetadata
is password protected.
Hope this helps
Cheenu
On 10/27/06, Peter
Giesin <pgiesin@xxxxxxxxxxxxxxxx>
wrote:
I
have the following XML that I need to parse into a POJO. I would
like to
use XMLBeans to accomplish this. So I created the following
schema. The
generated code parses anything without a namespace.
However, all the fields
with "metadata" as the name space don't seem
to get parsed. If I remove the
metadata tags from the XML everything
works fine. Unfortunately I cannot
easily remove this tags. I am
thinking that I could XSLT to do this.
However, before I went down
that road I was trying to determine if there
was some way that
XMLBeans could do it automatically.
Thanks,
Pete
XML:
<?xml version="1.0"
encoding="UTF-8"?>
<channel xmlns:metadata="http://beta.video.cnbc.com/rss/2.0/modules/
videoMetadata">
<title></title>
<link></link>
<description></description>
<language>en-us</language>
<copyright></copyright>
<pubDate>1158985570047</pubDate>
<image>
<title></title>
<link></link>
<url></url>
<width></width>
<height></height>
<description></description>
</image>
<item>
<title>The
eBay Effect: Pierre Omidyar Interview</title>
<link></link>
<description>Pierre
Omidyar
Interview</description>
<metadata:category>Apparel</metadata:category>
<metadata:category>B'cast
& Cable TV</metadata:category>
<metadata:category>Basic
Materials</metadata:category>
<metadata:category>Breaking
News</metadata:category>
<pubDate>1156405320000</pubDate>
<metadata:action>UPDATE</metadata:action>
<metadata:format>msmedia</metadata:format>
<metadata:id>77912236</metadata:id>
<metadata:thumbnail></metadata:thumbnail>
<metadata:show/>
<metadata:network>US</metadata:network>
<metadata:duration>104928</metadata:duration>
<metadata:market/>
<metadata:tickersymbol/>
<metadata:countryofnews/>
<metadata:guestname/>
<metadata:transcript/>
<metadata:transcripturl></metadata:transcripturl>
<metadata:bitrate>291024</metadata:bitrate>
<metadata:pid></metadata:pid>
<metadata:remainingshelflife>0</metadata:remainingshelflife>
<metadata:breakingnewsenddate>1156405440000</
metadata:breakingnewsenddate>
</item>
</channel>
Schema:
<?xml
version="1.0" encoding="UTF-8"?>
<xsd:schema
elementFormDefault="qualified" xmlns:xsd="http://
www.w3.org/2001/XMLSchema"
xmlns:metadata="
http://beta.video.cnbc.com/
rss/2.0/modules/videoMetadata">
<xsd:element
name="channel">
<xsd:complexType
mixed="true">
<xsd:choice
maxOccurs="unbounded" minOccurs="0">
<xsd:element
ref="title"/>
<xsd:element
ref="link"/>
<xsd:element
ref="description"/>
<xsd:element
ref="language"/>
<xsd:element
ref="copyright"/>
<xsd:element
ref="pubDate"/>
<xsd:element
ref="image"/>
<xsd:element
ref="item"/>
</xsd:choice>
</xsd:complexType>
</xsd:element>
<xsd:element
name="title"
type="xsd:string"/>
<xsd:element
name="link"
type="xsd:string"/>
<xsd:element
name="description" type="xsd:string"/>
<xsd:element
name="language"
type="xsd:string"/>
<xsd:element
name="copyright"
type="xsd:string"/>
<xsd:element
name="pubDate" type="xsd:string"/>
<xsd:element
name="image">
<xsd:complexType
mixed="true">
<xsd:choice
maxOccurs="unbounded" minOccurs="0">
<xsd:element
ref="title"/>
<xsd:element
ref="link"/>
<xsd:element
ref="url"/>
<xsd:element
ref="width"/>
<xsd:element
ref="height"/>
<xsd:element
ref="description"/>
</xsd:choice>
</xsd:complexType>
</xsd:element>
<xsd:element
name="url"
type="xsd:string"/>
<xsd:element
name="width" type="xsd:string"/>
<xsd:element
name="height"
type="xsd:string"/>
<xsd:element
name="item">
<xsd:complexType
mixed="true">
<xsd:choice
maxOccurs="unbounded" minOccurs="0">
<xsd:element
ref="title"/>
<xsd:element
ref="link"/>
<xsd:element
ref="description"/>
<xsd:element
ref="category"/>
<xsd:element
ref="pubDate"/>
<xsd:element
ref="action"/>
<xsd:element
ref="format"/>
<xsd:element
ref="id"/>
<xsd:element
ref="thumbnail"/>
<xsd:element
ref="show"/>
<xsd:element
ref="network"/>
<xsd:element
ref="duration"/>
<xsd:element
ref="market"/>
<xsd:element
ref="tickersymbol"/>
<xsd:element
ref="countryofnews"/>
<xsd:element
ref="guestname"/>
<xsd:element
ref="transcript"/>
<xsd:element
ref="transcripturl"/>
<xsd:element
ref="bitrate"/>
<xsd:element
ref="pid"/>
<xsd:element
ref="remainingshelflife"/>
<xsd:element
ref="breakingnewsenddate"/>
<xsd:element
ref="topstoryregion"/>
</xsd:choice>
</xsd:complexType>
</xsd:element>
<xsd:element
name="category"
type="xsd:string"/>
<xsd:element
name="action" type="xsd:string"/>
<xsd:element
name="format"
type="xsd:string"/>
<xsd:element
name="id"
type="xsd:string"/>
<xsd:element
name="thumbnail" type="xsd:string"/>
<xsd:element
name="show">
<xsd:complexType></xsd:complexType>
</xsd:element>
<xsd:element
name="network" type="xsd:string"/>
<xsd:element
name="duration"
type="xsd:string"/>
<xsd:element
name="market"
type="xsd:string"/>
<xsd:element
name="tickersymbol" type="xsd:string"/>
<xsd:element
name="countryofnews">
<xsd:complexType></xsd:complexType>
</xsd:element>
<xsd:element
name="guestname">
<xsd:complexType></xsd:complexType>
</xsd:element>
<xsd:element
name="transcript"
type="xsd:string"/>
<xsd:element
name="transcripturl" type="xsd:string"/>
<xsd:element
name="bitrate"
type="xsd:string"/>
<xsd:element
name="pid"
type="xsd:string"/>
<xsd:element
name="remainingshelflife" type="xsd:string"/>
<xsd:element
name="breakingnewsenddate"
type="xsd:string"/>
<xsd:element
name="topstoryregion"
type="xsd:string"/>
</xsd:schema>
---------------------------------------------------------------------
To
unsubscribe, e-mail: user-unsubscribe@xxxxxxxxxxxxxxxxxxx
For
additional commands, e-mail: user-help@xxxxxxxxxxxxxxxxxxx
_______________________________________________________________________
Notice: This email message, together with any attachments, may contain
information of BEA Systems, Inc., its subsidiaries and affiliated
entities, that may be confidential, proprietary, copyrighted and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.