The primary schema declaration looks like this on-disk:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
elementFormDefault="qualified" attributeFormDefault="unqualified">

It's updated in-memory to this:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
xmlns="http://www.company.com/schemas/servermain";
elementFormDefault="qualified" attributeFormDefault="unqualified"
targetNamespace="http://www.company.com/schemas/servermain";>

To do so, I load the schema and:
1.) xmlDocGetRootElement
2.) xmlSetProp with "targetNamespace"
3.) xmlSetProp with "xmlns"

Is this the wrong way to go about this? Should I be using the NS-specific
API's for step 3?

The import nodes that I am adding look like this:
<xs:import namespace="http://www.company.com/schemas/simulator";
schemaLocation="file:///home/pcameron/shared/debug/bin/schemas/simulator.xsd
"/><xs:element name="Project">

One indication that something may be amiss is the way that the first
<xs:element> is dumped without spacing (the rest of the doc is
spaced/indented correctly with xmlDocDump).

The following steps are used to create these nodes:

1.) xmlDocGetRootElement
2.) xmlFirstElementChild (I need to insert <xs:import> as the first child of
<xs:schema>
3.) xmlNewNode with "xs:import" 
4.) xmlDocCopyNode to populate the new node with doc info
5.) xmlAddPrevSibling to insert the new node in front of the previous
first-child-element.
6.) xmlSetProp with "namespace" to setup the namespace attribute
7.) xmlSetProp with "schemaLocation" to setup the file URI for the import
schema

Finally, the imported schemas (which are not manipulated in-memory) have
declarations that look like this:
<xs:schema 
xmlns:xs="http://www.w3.org/2001/XMLSchema"; 
elementFormDefault="qualified" 
attributeFormDefault="unqualified"
xmlns="http://www.company.com/schemas/simulator";
xmlns:simulator="http://www.company.com/schemas/simulator";
targetNamespace="http://www.company.com/schemas/simulator";>

So, does anything seem blatantly incorrect here?

Thanks again,
- Paul


-----Original Message-----
From: Daniel Veillard [mailto:veill...@redhat.com] 
Sent: Wednesday, May 25, 2011 10:51 PM
To: Paul B. Cameron
Cc: xml@gnome.org
Subject: Re: [xml] XML Schema: Validating an instance document with multiple
schemas

On Mon, May 23, 2011 at 03:50:37PM -0400, Paul B. Cameron wrote:

> Just to be sure I'm clear, this case fails:
> 
> 1.) xmlReadFile (strPrimarySchemaFile, NULL, XML_PARSE_NONET)
> 
> 2.) Add targetNamespace to xs:schema node for primary schema, add
> <xs:import> nodes for secondary schemas
> 
> 3.) call xmlSchemaNewDocParserCtxt to create parser context and
> xmlSchemaParse to parse the schema (which fails)

  This smells like in doing 2 you missed something with namespaces,
and that as a result when parsing your in-memory tree teh XSD parser
fails to find the namespaces (maybe just the prefix or something.

> 
> And this case succeeds:
> 
> 1.) Call xmlReadFile like before
> 
> 2.) Add targetNamespace and xs:import's exactly like above
> 
> 3.) Call xmlDocDumpMemory to dump to a xmlChar buffer, xmlDocFree to free
> the original doc, and xmlReadDoc load the dumped buffer back into a DOM

  here after serialization and reparsing the namespaces of the elements
and attributes in the tree are fine, and then everything works as
expected.

> 4.) Call xmlSchemaNewDocParserCtxt and xmlSchemaParse as above (and
> ultimately xmlSchemaValidateDoc), which now succeed 

 Triple-check the namespaces pointers and of the new elements/attributes
you added to the tree, not by serializing them but by looing at the
actual ns and nsDef pointers.

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
dan...@veillard.com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/

_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xml@gnome.org
http://mail.gnome.org/mailman/listinfo/xml

Reply via email to