You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by VitaminSmooth <vi...@gmail.com> on 2011/06/02 16:55:29 UTC

Validation of Instance Extended Through 'any' Element

I have two schemas: a base schema that is extensible through an 'any'
element, and an extension schema that defines the element I expect to find
there for a certain project.


base schema fragment:

<xsd:complexType name="custom">
    <xsd:sequence minOccurs="0" maxOccurs="unbounded">
        <xsd:any namespace="##any" processContents="lax"
maxOccurs="unbounded"/>
    </xsd:sequence>
</xsd:complexType>
<xsd:element ref="custom"/>


extension schema fragment:

<xsd:element name="somethingnew">
    ...
</xsd:element>


instance fragment:

<custom>
    <somethingnew>
        ...
    </somethingnew>
</custom>


Using Xerces-C, I can validate the file using the base schema, which will
accept any well-formed xml in place of the 'any' element.  My question is
how do I validate the 'somethingnew' element using the separate extension
schema?  I could modify a copy of the base schema to include the extension
element, but I'd like to be able to use the two files in their unmodified
forms, as they are standard documents.  Can I somehow load both schemas into
a grammar pool and validate the whole instance?

I'd really appreciate any help.  Thanks for sharing your knowledge!
-- 
View this message in context: http://old.nabble.com/Validation-of-Instance-Extended-Through-%27any%27-Element-tp31758318p31758318.html
Sent from the Xerces - C - Users mailing list archive at Nabble.com.


Re: Validation of Instance Extended Through 'any' Element

Posted by VitaminSmooth <vi...@gmail.com>.
Follow up:

After adding a namespace to the extension schema and tweaking a bit, I was
able to get this to work using your suggestion.  Thanks!

There are two things I don't love about this solution:

First, I have to add a namespace to the externsion schema, which I do not
maintain or have control over.  However, I guess it's really the proper
thing to do, as most parsers are processing namespaces now.  

Second, the externalSchemaLocation setting does not give me control over
which schema files get loaded, as the parser seems to check the directory
where the instance file is located first.  I was using loadGrammar() to
cache the schema files in advance, and that allowed me to specify exactly
which files to load.  My understanding is that I may have to implement an
entityResolver to control that.



Vitaly Prapirny wrote:
> 
> You can define namespaces for base and extension schemas and then set
> parser property XMLUni::fgXercesSchemaExternalSchemaLocation accordingly
> ("base_schema_ns base_schema.xsd extension_schema_ns ext_schema.xsd")
> 
> Good luck!
> 	Vitaly
> 
> 

-- 
View this message in context: http://old.nabble.com/Validation-of-Instance-Extended-Through-%27any%27-Element-tp31758318p31795714.html
Sent from the Xerces - C - Users mailing list archive at Nabble.com.


Re: Validation of Instance Extended Through 'any' Element

Posted by Vitaly Prapirny <ma...@mebius.net>.
You can define namespaces for base and extension schemas and then set
parser property XMLUni::fgXercesSchemaExternalSchemaLocation accordingly
("base_schema_ns base_schema.xsd extension_schema_ns ext_schema.xsd")

Good luck!
	Vitaly

VitaminSmooth wrote:
>
> I have two schemas: a base schema that is extensible through an 'any'
> element, and an extension schema that defines the element I expect to find
> there for a certain project.
>
>
> base schema fragment:
>
> <xsd:complexType name="custom">
>      <xsd:sequence minOccurs="0" maxOccurs="unbounded">
>          <xsd:any namespace="##any" processContents="lax"
> maxOccurs="unbounded"/>
>      </xsd:sequence>
> </xsd:complexType>
> <xsd:element ref="custom"/>
>
>
> extension schema fragment:
>
> <xsd:element name="somethingnew">
>      ...
> </xsd:element>
>
>
> instance fragment:
>
> <custom>
>      <somethingnew>
>          ...
>      </somethingnew>
> </custom>
>
>
> Using Xerces-C, I can validate the file using the base schema, which will
> accept any well-formed xml in place of the 'any' element.  My question is
> how do I validate the 'somethingnew' element using the separate extension
> schema?  I could modify a copy of the base schema to include the extension
> element, but I'd like to be able to use the two files in their unmodified
> forms, as they are standard documents.  Can I somehow load both schemas into
> a grammar pool and validate the whole instance?
>
> I'd really appreciate any help.  Thanks for sharing your knowledge!