Hi Jim

I can answer your first question. I'll have to leave someone else to
answer your second.

Your schema defines a targetNamespace of
"http://www.aptas.com/ontology";. datafeed is defined as a top-level
(i.e. global) element. This means that instance documents need to refer
to that element using a qualified approach i.e. using both the namespace
and the local name of datafeed.

However you have also defined elementFormDefault="unqualified". This
means that all local elements _must_ be referred to in an unqualified
way i.e. without a namespace (you can override this default on
individual elements with form="qualified|unqualified", but that's not
relevant to your problem below).

Defining xmlns="http://www.aptas.com/ontology"; does the right thing to
the datafeed element (qualifies it with that namespace) but
unfortunately it does the same thing to all child elements as well which
is incorrect.

You can either do as you suggested and in the instance document define
xmlns:xxx="http://www.aptas.com/ontology"; and then use xxx as a prefix
_only_ on your global elements. Or you can change your schema such that
elementFormDefault="qualified". Then validation will expect both global
and local elements to be namespace-qualified and you can use the
instance document you have below.

Cheers,

Lawrence

> -----Original Message-----
> From: Jim McMaster [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, May 24, 2005 1:06 PM
> To: [email protected]
> Subject: Problems with namespace prefixes in version 2
> 
> 
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> I am using XmlBeans v2 to access appinfo elements in a schema, which
> I then process to create XML based on that schema.  A portion of the
> schema is:
> 
> <?xml version="1.0"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
>     xmlns:ontology="http://www.aptas.com/ontology";
>     xmlns:papyrus="http://www.aptas.com/papyrus";
>     targetNamespace="http://www.aptas.com/ontology";
>     elementFormDefault="unqualified"
>     attributeFormDefault="unqualified">
>     <xs:import namespace="http://www.aptas.com/papyrus";
>         schemaLocation="xsd/PapyrusAppinfo.xsd" />
>     <xs:complexType name="ontology">
>         ...omitted for brevity
>     </xs:complexType>
>     <xs:element name="datafeed">
>         <xs:complexType>
>             <xs:sequence>
>                 <xs:element name="ontology" type="ontology:ontology">
>                 </xs:element>
>             </xs:sequence>
>             <xs:attribute name="locale" type="xs:language"
>                 default="en">
>             </xs:attribute>
>         </xs:complexType>
>     </xs:element>
> </xs:schema>
> 
> A sample of the generated XML is:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <datafeed xmlns="http://www.aptas.com/ontology"; locale="en-US">
>     <ontology>
>       ...stuff omitted
>     </ontology>
> </datafeed>
> 
> The problem is, this XML does not validate against the schema.  The
> only way I can get it to validate is to define the namespace prefix
> "ontology" in the XML, then prefix the datafeed element, and only the
> datafeed element, with "ontology:".
> 
> The first question, non-XmlBeans-related, is why the datafeed element
> needs to be prefixed?  I am hoping a schema guru can educate me.
> 
> The second question is, I can't find the prefix to add.  When I get
> the SchemaTypeSystem from the XmlBeans compiler, the SchemaType and
> the SchemaLocalElement for the datafeed element both have a QName
> with a correct namespaceURI and localPart, but the prefix is an empty
> string.  Assuming I really need it, where can I find the prefix?
> 
> Thank you.  If I have not provided enough information, please let me
> know and I will send more.
> 
> 
> - --
> Jim McMaster
> mailto:[EMAIL PROTECTED]
> 
> 
> -----BEGIN PGP SIGNATURE-----
> Version: PGP 8.1
> 
> iQA/AwUBQpOJOmaP5l7/atSJEQJayQCfUoyPcRTXuHgYSE4MvYm3JA18DMwAn2Uo
> 7e81Xxzf/nHOIN+3WTbKVg4p
> =fwFK
> -----END PGP SIGNATURE-----
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to