Re: XMLBean Document Objects

Peter Keller <[email protected]> Thu, 27 May 2010 19:52:44 +0100 (BST)
Newsgroups gmane.text.xml.xmlbeans.user
Message-ID <[email protected]>
Hi Duane,

In order to have non-empty documents that are valid with respect to an XML 
schema, a root element must be defined in the schema. This is not a 
limitation of XMLBeans, but an aspect of the way that XML schema works.

If you cannot modify the schema by adding a root element definition, I 
suggest that you define a new, trivial, schema that imports the one that you 
are working with now, and define the root element in that. You should be 
able to use the same target namespace in both schema files. If you then use 
this new trivial schema as the input to scomp, you should get 
FooDocument.java. You may need to add a "schemaLocation" attribute to your 
<xsd:import...> element to get scomp to pull in the type definition 
automatically.

Good luck,
Peter.

On Thu, 27 May 2010, Duane Zamrok wrote:

> Hello,
> 
> IΒ’m working with an XML schema that defines a complex type but not an element of that type. This means that when I compile the schema
> with XMLBeans I get FooType.java but not a FooDocument.java. However, IΒ’d like to be able to parse documents whose root element has been
> defined to be of type Foo. Is this possible with XMLBeans or should I simply pursue a manual parsing alternative?
> 
> Β 
> 
> Β 
> 
> Example Schema
> 
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:org:test:namespace" elementFormDefault="qualified">
> Β Β Β  <xs:complexType name="FooType">
> Β Β Β Β Β Β Β  <xs:sequence>
> Β Β Β Β Β Β Β Β Β Β Β  <xs:element name="bar" type="xs:string"/>
> Β Β Β Β Β Β Β  </xs:sequence>Β Β Β Β Β Β Β 
> Β Β Β  </xs:complexType>
> </xs:schema>
> 
> Β 
> 
> Example Document
> 
> <someElementName xmlns:tst="urn:org:test:namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="tst:FooType">
> Β Β Β  <tst:bar>some value</tst:bar>Β Β Β 
> </someElementName>
> 
> Β 
> 
> Thanks
> 
> -Duane
> 
> 
>

-- 
Peter Keller                                     Tel.: +44 (0)1223 353033
Global Phasing Ltd.,                             Fax.: +44 (0)1223 366889
Sheraton House,
Castle Park,
Cambridge CB3 0AX
United Kingdom


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]