Hi Alberto,

Thanks very much. But my dilemma is that a.xsd (or d.xsd in your
proposed solution) is trying to use something in b.xsd, and b.xsd is
trying to use something in c.xsd, so I have this nested <import>ing
thing. I guess I will have to change this in the schemas in order to use
Xerces.

Thanks again.
Frank

-----Original Message-----
From: Alberto Massari [mailto:[EMAIL PROTECTED] 
Sent: Friday, September 15, 2006 1:38 AM
To: [email protected]
Subject: RE: valid schema can not be loaded using Xerces 2.7

Hi Frank,

At 09.24 14/09/2006 -0700, Frank Zhou wrote:
>Hi Alberto,
>
>Thanks for the explanation. So what are the best wordarounds then? 
>Although modifying the schemas really not an option for me (I got the 
>issue from one of my biggest customer, and they have standardize their 
>schemas this way, also seems like all other tools like XMLSpy can load 
>their schemas), I still would like to explore them. It seems to me that

>I don't have a solution here, because in my real user case, a.xsd will 
>use some types in b.xsd, and b.xsd will use some types in c.xsd, so 
>even if I have a.xsd including c.xsd, I still can not let a.xsd import 
>b.xsd, and b.xsd import a.xsd (instead of c.xsd), this won't work 
>either, right?
>
>As a workaround, is it possible that I just change the Xerces code to 
>keep loading the grammar even if it is found in the pool? I mean, in 
>preprocessImport in traverseSchema.cpp, remove the lines if 
>(grammarFound) return;

No, or you will get an infinite loop if you load a.xsd that imports
b.xsd that imports a.xsd.
An approach you could try is creating d.xsd like this

<xs:schema xmlns="http://www.xyz.org/XYZ"; 
xmlns:xs="http://www.w3.org/2001/XMLSchema"; 
xmlns:ABC="http://www.xyz.org/ABC";
targetNamespace="http://www.xyz.org/XYZ";>
   <xs:include schemaLocation="c.xsd"/>
   <xs:include schemaLocation="a.xsd"/>
</xs:schema>

and then register an entity resolver that provides this schema file
whenever resolveEntity is invoked with the namespace
http://www.xyz.org/XYZ and the flag XMLResourceIdentifier::SchemaImport.

Hope this helps,
Alberto


>Thanks.
>Frank
>
>
>
>
>--- Alberto Massari <[EMAIL PROTECTED]> wrote:
>
> > Hi Frank,
> > the fact that you don't use <import> twice doesn't remove the 
> > constraint that there can only be one official location for each 
> > targetNamespace. In your case, both a.xsd and c.xsd have the same 
> > targetNamespace, and having both of them in the import chain will 
> > ignore one of the two.
> >
> > Alberto
> >
> > At 09.30 13/09/2006 -0700, Xiaofan Zhou wrote:
> > >Alberto,
> > >
> > >But in my case, I never "import" the same namespace
> > more than once,
> > >notice a.xsd and c.xsd have the same namespace but
> > complete different
> > >content, and b.xsd has a different namespace. Here
> > is the sequence:
> > >
> > >a.xsd (say has a namespace1)
> > >    |-----import namespace2, location="b.xsd"
> > >
> > |--------------------import namespace1
> > >location="c.xsd"
> > >
> > >=====
> > >Now when I loadGrammar like this:
> > >
> > >Parser->loadGramma(inputSource(a),
> > schemaGrammarType)
> > >
> > >The Xerces logic seems like this (if I read
> > correctly)
> > >
> > >1)  the grammarPool has an item of namespace1, but
> > really nothing there,
> > >because we are just at the beginning of a.xsd
> > >2)  processing import namespace2, as this is the
> > first statement of
> > >a.xsd
> > >3)  processing import namespace1, as this is the
> > first statement of
> > >b.xsd
> > >     Now when Xerces does this, it checks the
> > grammarPool to see if
> > >namespace1 is there, it found it and stop loading
> > >     c.xsd.
> > >
> > >This does not make sense to me.
> > >
> > >Thanks.
> > >
> > >Frank
> > >
> > >
> > >
> > >
> > >
> > >-----Original Message-----
> > >From: Alberto Massari
> > [mailto:[EMAIL PROTECTED]
> > >Sent: Wednesday, September 13, 2006 12:53 AM
> > >To: [email protected]
> > >Subject: Re: valid schema can not be loaded using
> > Xerces 2.7
> > >
> > >At 13.01 12/09/2006 -0700, Frank Zhou wrote:
> > > >Hi All,
> > > >
> > > >I have the attached simple schemas a, b, and c,
> > in which a import b,
> > > >and b import c, a and c have the same target
> > namespace, but b have a
> > > >different target namespace.
> > > >
> > > >[...]
> > > >I always get the type not found error for a type
> > defined in schema.
> > > >
> > > >However, if I use schema b as the root, I don't
> > have a problem. And I
> > > >debugged the Xerces code, seems like in
> > preprocessImport (in
> > > >traverseSchema.cpp), when try to resolve schema
> > c, because it have the
> > > >same target namespace as a, and it thinks grammar
> > already found, so
> > > >stop loading types from schema c.
> > >
> > >Hi Frank,
> > >the behavior of Xerces is allowed by the specs; see
> > the note in
> > >$4.2.3 "Note: The above is carefully worded so that
> > multiple <import>ing
> > >of the same schema document will not constitute a
> > violation of clause 2
> > >of Schema Properties Correct ( 3.15.6), but
> > applications are allowed,
> > >indeed encouraged, to avoid <import>ing the same
> > schema document more
> > >than once to forestall the necessity of
> > establishing identity component
> > >by component. Given that the schemaLocation
> > [attribute] is only a hint,
> > >it is open to applications to ignore all but the
> > first <import> for a
> > >given namespace, regardless of the actual value of
> > schemaLocation, but
> > >such a strategy risks missing useful information
> > when new
> > >schemaLocations are offered."
> > >So you should design your schemas to have a single
> > .xsd as the official
> > >repository for a given targetNamespace, and have it
> > include all the
> > >other pieces.
> > >
> > >Hope this helps,
> > >Alberto
> > >
> > >
> > > >I tried to use my own entityResolver as well as
> > the default one.
> > > >
> > > >Is this a bug in Xerces or I need to set up my
> > parser differently?
> > > >
> > > >Thanks much.
> > > >Frank
> > > >
> > >
> > >__________________________________________________
> > > >Do You Yahoo!?
> > > >Tired of spam?  Yahoo! Mail has the best spam
> > protection around
> > > >http://mail.yahoo.com <?xml version="1.0"
> > encoding="UTF-8"?> <xs:schema
> > >
> > > >xmlns="http://www.xyz.org/XYZ";
> > > >xmlns:xs="http://www.w3.org/2001/XMLSchema";
> > > >xmlns:ABC="http://www.xyz.org/ABC";
> > > >targetNamespace="http://www.xyz.org/XYZ";
> > > >elementFormDefault="qualified"
> > attributeFormDefault="unqualified">
> > > >         <xs:import
> > namespace="http://www.xyz.org/ABC";
> > > > schemaLocation="b.xsd"/>
> > > >         <xs:element name="E1">
> > > >             <xs:complexType>
> > > >                <xs:sequence>
> > > >                    <xs:element name="E3"
> > type="e3Type"/>
> > > >                </xs:sequence>
> > > >            </xs:complexType>
> > > >         </xs:element>
> > > ></xs:schema>
> > > >
> > > ><?xml version="1.0" encoding="UTF-8"?>
> > > ><xs:schema
> > xmlns:xs="http://www.w3.org/2001/XMLSchema";
> > > >xmlns:ABC="http://www.xyz.org/ABC";
> > > >xmlns:XYZ="http://www.xyz.org/XYZ";
> > xmlns="http://www.xyz.org/ABC";
> > > >targetNamespace="http://www.xyz.org/ABC";
> > > >elementFormDefault="qualified"
> > attributeFormDefault="unqualified">
> > > >         <xs:import
> > namespace="http://www.xyz.org/XYZ";
> > > > schemaLocation="c.xsd"/>
> > > >         <xs:element name="E2" type="XYZ:e2Type">
> > > >         </xs:element>
> > > ></xs:schema>
> > > >
> > > ><?xml version="1.0" encoding="utf-8"?>
> > > ><xs:schema xmlns="http://www.xyz.org/XYZ";
> > > >xmlns:xs="http://www.w3.org/2001/XMLSchema";
> > > >xmlns:ABC="http://www.xyz.org/ABC";
> > > >targetNamespace="http://www.xyz.org/XYZ";
> > > >elementFormDefault="qualified"
> > attributeFormDefault="unqualified">
> > > >         <xs:simpleType name="e2Type">
> > > >                 <xs:restriction base="xs:int"/>
> > > >         </xs:simpleType>
> > > >         <xs:simpleType name="e3Type">
> > > >                 <xs:restriction
> > base="xs:string"/>
> > > >         </xs:simpleType>
> > > ></xs:schema>
> > > >
> > > >
> > >
> >
> >---------------------------------------------------------------------
> > > >To unsubscribe, e-mail:
> > [EMAIL PROTECTED]
> > > >For additional commands, e-mail:
> > [EMAIL PROTECTED]
> > >
> >
>=== message truncated ===
>
>
>__________________________________________________
>Do You Yahoo!?
>Tired of spam?  Yahoo! Mail has the best spam protection around
>http://mail.yahoo.com
>
>---------------------------------------------------------------------
>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]

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

Reply via email to