[
Lists Home |
Date Index |
Thread Index
]
Ah! Got it.
It makes sense now that you've explained it. It sort of makes me feel silly
for not figuring it out on my own, since I'd done the same thing in all the
references I'd made in the xsd files.
I think I have things working now.
Thanks for all your help Jeff!
-----Original Message-----
From: Jeff Rafter [mailto:lists@jeffrafter.com]
Sent: Tuesday, May 23, 2006 3:09 PM
To: Darren Hall
Cc: 'XML-Dev Mailing list'
Subject: Re: [xml-dev] Namespace trouble (was xsd : root element not found)
> It seems to me that what you're saying is that all of my elements for this
> xml schema must exist in the same namespace. Obviously that's not what I'm
> doing since my schema is made up of modular elements that can be combined
to
> form new schemas as needed for new types of publications (I'm attempting
to
> model several types of publications with my modular schema design).
No, that isn't what I am saying :) I am saying that if you want your
elements to be in other namespaces (as your schemas indicated) then you
have to make sure that you utilize those namespaces in your instance
documents.
In your sample:
<?xml version="1.0" encoding="utf-8"?>
<standaloneArticle
xmlns="http://globals.namespace.org/content/xml/xsd/v10/article/single/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://globals.namespace.org/content/xml/xsd/v10/article
/single/
standaloneArticle.xsd">
<article>
</article>
</standaloneArticle>
The article element is actually
{http://globals.namespace.org/content/xml/xsd/v10/article/single/}article
But what you really want is a
{http://globals.namespace.org/content/xml/xsd/v10/article/}article
This is happening because the xmlns declaration on the root element is
saying that if there is no prefix, use the default namespace. So you
need to (a) add a new default namespace declaration to the <article>
element (b) add a prefixed namespace declaration to the element and
specify the prefix: i.e.,
<art:article
xmlns:art="http://globals.namespace.org/content/xml/xsd/v10/article/"/>
Here the prefix is "art" and it indicates the article namespace.
In the original email I gave you a third option which was to leave the
instance document as is and change the schema so everything was in the
same namespace. But, as you stated you don't want to do that, so you are
left with option a or b.
In terms of how namespaces work I could suggest a few good books ;) or
point you to the namespaces Recommendation
http://www.w3.org/TR/REC-xml-names/ There are probably great tutorials
online as well-- but others will have to point out the links. In terms
of how namespaces and XML Schemas work and the different styles, I might
recommend Roger Costello's XML Schema Best Practices guide.
Cheers,
Jeff Rafter
>
>
> Where can I look to find out how to do what I'm attempting? Or in lieu of
> that, what more information would the group need to point me in the right
> direction?
>
> Thanks,
>
> Darren
>
> -----Original Message-----
> From: Jeff Rafter [mailto:lists@jeffrafter.com]
> Sent: Tuesday, May 23, 2006 12:44 PM
> To: Darren Hall
> Cc: 'XML-Dev Mailing list'
> Subject: Re: [xml-dev] Namespace trouble (was xsd : root element not
found)
>
> You haven't given us quite enough to give you the full solution. But the
> problem is evident. The <article> element must be qualified with a
> different namespace (specifically:
> "http://globals.namespace.org/content/xml/xsd/v10/article/") so
> something like:
>
> <art:article
> xmlns:art="http://globals.namespace.org/content/xml/xsd/v10/article/"/>
>
> should work. Right now, because of the default xmlns, you are suggesting
> that <article> is in the
> "http://globals.namespace.org/content/xml/xsd/v10/article/single/"
> namespace.
>
>
> Keep in mind, you declared a namespace in article.xsd. There that global
> element definition must be qualified with that namespace name regardless
> of where it is referenced. You import it into your schema and then reuse
> it using a ref, so it definitely must be qualified with the original
> namespace.
>
> there are workarounds to have separate modules and one global namespace.
> But we would need to see more to give you the full breakdown.
>
> Cheers,
> Jeff Rafter
>
>
> Darren Hall wrote:
>> Hello again.
>>
>> I'm having trouble validating an xml file I've created against an xsd
I've
>> made. I'm trying to use a modular design in my XML Schema so that I can
> get
>> reuse out of elements I've defined. I'm using XMLSpy Home as my
validation
>> tool.
>>
>> When I attempt to validate my xml document, I'm getting the message that
>> it's hitting an unexpected element. Ironically, the unexpected element is
> in
>> fact the element it should be expecting. I believe the problem may be
>> related to namespace (which I'm not very good with).
>>
>> Can anyone help me with this, or point me in the direction of a page that
>> might help? Any help would be appreciated. Thanks.
>>
>> Darren
>>
>> **relevant code**
>>
>> [from article.xml - the document being validated]
>>
>> <?xml version="1.0" encoding="utf-8"?>
>> <standaloneArticle
>> xmlns="http://globals.namespace.org/content/xml/xsd/v10/article/single/"
>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>
>>
>
xsi:schemaLocation="http://globals.namespace.org/content/xml/xsd/v10/article
>> /single/ standaloneArticle.xsd">
>> <article>
>> ...
>> </article>
>> </standaloneArticle>
>>
>> ----------------------------------
>> [from standaloneArticle.xsd]
>> <?xml version="1.0" encoding="UTF-8" ?>
>> <xs:schema
>>
>
targetNamespace="http://globals.namespace.org/content/xml/xsd/v10/article/si
>> ngle/"
>> xmlns:sar="http://globals.
>> namespace.org/content/xml/xsd/v10/article/single/"
>> xmlns:art="http://globals.namespace.org/content/xml/xsd/v10/article/"
>> xmlns:ref="http://globals.namespace.org/content/xml/xsd/v10/reference/"
>> xmlns:xs="http://www.w3.org/2001/XMLSchema"
>> elementFormDefault="qualified"
>> attributeFormDefault="qualified">
>> <!-- import of external definitions -->
>> <xs:import
>> namespace="http://globals.namespace.org/content/xml/xsd/v10/article/"
>> schemaLocation="article.xsd"/>
>> <xs:import
>> namespace="http://globals.namespace.org/content/xml/xsd/v10/reference/"
>> schemaLocation="reference.xsd"/>
>> <!-- definition of complex type elements -->
>> <xs:element name="standaloneArticle">
>> <xs:complexType>
>> <xs:sequence>
>> <xs:element ref="art:article" minOccurs="1" maxOccurs="1"/>
>> <xs:element ref="ref:reference" minOccurs="1" maxOccurs="1"/>
>> </xs:sequence>
>> </xs:complexType>
>> </xs:element>
>> </xs:schema>
>>
>> ----------------------------------
>> [from article.xsd]
>> <?xml version="1.0" encoding="UTF-8" ?>
>> <xs:schema
>>
>
targetNamespace="http://globals.namespace.org/content/xml/xsd/v10/article/"
>>
>> xmlns:art="http://globals.namespace.org/content/xml/xsd/v10/article/"
>>
>> xmlns:aut="http://globals.namespace.org/content/xml/xsd/v10/author/"
>>
>> xmlns:sty="http://globals.namespace.org/content/xml/xsd/v10/style/"
>> xmlns:xs="http://www.w3.org/2001/XMLSchema"
>> elementFormDefault="qualified"
>> attributeFormDefault="qualified">
>> <!-- import of external definitions -->
>> ...
>> </xs:schema>
>>
>>
>>
>> -----------------------------------------------------------------
>> The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
>> initiative of OASIS <http://www.oasis-open.org>
>>
>> The list archives are at http://lists.xml.org/archives/xml-dev/
>>
>> To subscribe or unsubscribe from this list use the subscription
>> manager: <http://www.oasis-open.org/mlmanage/index.php>
>>
>>
>
> -----------------------------------------------------------------
> The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
> initiative of OASIS <http://www.oasis-open.org>
>
> The list archives are at http://lists.xml.org/archives/xml-dev/
>
> To subscribe or unsubscribe from this list use the subscription
> manager: <http://www.oasis-open.org/mlmanage/index.php>
>
>
>
>
>
> -----------------------------------------------------------------
> The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
> initiative of OASIS <http://www.oasis-open.org>
>
> The list archives are at http://lists.xml.org/archives/xml-dev/
>
> To subscribe or unsubscribe from this list use the subscription
> manager: <http://www.oasis-open.org/mlmanage/index.php>
>
>
-----------------------------------------------------------------
The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
initiative of OASIS <http://www.oasis-open.org>
The list archives are at http://lists.xml.org/archives/xml-dev/
To subscribe or unsubscribe from this list use the subscription
manager: <http://www.oasis-open.org/mlmanage/index.php>
|