Re: [xml] XML Schema: Validating an instance document with multiple schemas

The primary schema declaration looks like this on-disk:
<xs:schema xmlns:xs="";
elementFormDefault="qualified" attributeFormDefault="unqualified">

It's updated in-memory to this:
<xs:schema xmlns:xs="";
elementFormDefault="qualified" attributeFormDefault="unqualified"

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="";
"/><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
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
6.) xmlSetProp with "namespace" to setup the namespace attribute
7.) xmlSetProp with "schemaLocation" to setup the file URI for the import

Finally, the imported schemas (which are not manipulated in-memory) have
declarations that look like this:

So, does anything seem blatantly incorrect here?

Thanks again,
- Paul

-----Original Message-----
From: Daniel Veillard [mailto:veillard 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

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

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 Veillard      | libxml Gnome XML XSLT toolkit
daniel veillard com  | Rpmfind RPM search engine | virtualization library

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]