EDIT:Preface:
Below is a particular instance of the problem described in the title. I have a single namespace shared by two documents; one imports the other. However, the import seems to confuse the namespace attribute on element"any".
The Goal:
To have the xml validate; "any" element should check only the target namespace for elements. I.e., Only element "stuff" or "Product" (and it's children) should validate.
The Error:
"The matching wildcard is strict, but no declaration can be found for element 'stuff'." I want strict matching!
Schema 1:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.company.org"
xmlns="http://www.company.org"
elementFormDefault="qualified">
<xsd:include schemaLocation="http://www.product.org"/>
<xsd:element name="Company">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Product" type="ProductType"
maxOccurs="unbounded"/>
<xsd:element name="stuff" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
Schema 2:
<xsd:schema
xmlns="http://www.company.org"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.company.org"
elementFormDefault="qualified"
>
<xsd:complexType name="ProductType">
<xsd:sequence>
<xsd:any minOccurs="1" maxOccurs="unbounded"
namespace="targetNamespace" />
</xsd:sequence>
</xsd:complexType>
XML:
<?xml version="1.0"?>
<Company xmlns="http://www.company.org"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.company.org /u/name/test/file1.xsd"
>
<Product>
<stuff>Widget</stuff>
</Product>
<stuff>text</stuff>
</Company>
EDIT: Thoughts:
Based on the error, it looks as if the xml can't find the schema that declares "stuff", which is the targetNamespace, "http://www.company.org! I'm lost as to why this is the case. Help would be GREATLY appreciated, as this problem has been bugging me for 2 days now.
EDIT 2: Solution:
Schema 1 (http://www.company.org):
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.company.org"
xmlns="http://www.company.org"
elementFormDefault="qualified">
<xsd:include schemaLocation="http://www.product.org"/>
<xsd:element name="Company">
<xsd:complexType>
<xsd:choice minOccurs="0" maxOccurs="unbounded" >
<xsd:any namespace="##targetNamespace" />
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Schema 2 (http://www.product.org):
<xsd:schema
xmlns="http://www.company.org"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.company.org"
elementFormDefault="qualified"
>
<xsd:simpleType name="stuff">
<xsd:restriction base="xsd:string" />
</xsd:simpleType>
<xsd:complexType name="ProductType">
<xsd:sequence>
<xsd:any minOccurs="1" maxOccurs="unbounded"
namespace="http://www.company.org" processContents="strict" />
</xsd:sequence>
</xsd:complexType>
<xsd:element name="Product" type="ProductType" />
<xsd:element name="stuff" type="stuff" />
</xsd:schema>
This solution has worked beautifully for me so far. Element "any namespace="##targetNamespace" /" will find each element included in the central, including file. The beauty is in that with this set up, the namespace is homogeneous, so I can ignore prefixes in both the xml and xsd files, while including any number of supporting schema, but I only need one file to validate against.
Feedback welcome :D