Re: [xml] Where can I get the declaration of a non global element in xmlSchema (using libxml2-2.6.22) ?



Hi,

On Wed, 2005-09-14 at 15:28 +0200, GUY Fabrice wrote:
Hi,

With libxml2 version 2.6.21 I could retrieve the declaration of an
element (using xmlHashScan(schema->elemDecl, ..., ...).

Unfortunately, it doesn't seem to be possible with the new release (I
can get only global element declarations with this method).

Yes, this changed. Originally the hash tables were used to hold all
components of one particular schema, thus you could access
only the components of the main schema, since imported/included
schemas were not exposed to the API.

Later the tables were changed to hold _all_ components of _all_
schemas; this was the state you are missing now.

From 2.6.22 on the story goes like this:
(look at the picture below if the description starts to make no sense)

The hash tables of a xmlSchema are intended to be used only to access
global components using the name and target-namespace as the search
criterion; e.g. when resolving references to other components or during
instance validation. There is an internal graph of schemas, which
reflects relationships between imported/included/redefined schemas.
For each _imported_ target-namespace (plus for the target-namespace
of the main schema) there's exactly one xmlSchema in the schema graph.
Each of those schemas holds only global components of the same
target-namespace. For _every_ imported/included/redefined schema,
plus the main schema, there is exactly one schema "bucket", which
holds _all_ components of _one_ specific schema document.
So the components reside in different slots, depending on
the target-namespace and global/local.

Example:

"main-schema" and "included-schema" have the target-namespace
"urn:test:FOO".

"imported-schema" has the target-namespace "urn:test:BAR".

"main-schema"                  <- bucket: all components of this schema
  |                            <- schema: all global comps. with
  |                                "urn:test:FOO" to be used for
  |                                lookups; this includes components
  |                                from "included-schema"
  |
  --- "included-schema"        <- bucket: all components of this schema
         |
         --- "imported-schema" <- bucket: all components of this schema
                               <- schema: all global comps. with
                                         "urn:test:BAR" to be used
                                         for lookups

What we could do to make your life more pleasant, is to try to expose
the [schema information] PSVI for element information items [1].

But please avoid using direct access to the structure members of the
schema components. Some of the fields of those structures are obsolete
for historical reasons; plus some of the component structures are not
even public: model group definitions, model-groups, particles,
all of identity-constraints - all not public.

Hmm, let's try a deal: if I would expose the above mentioned PSVI,
would you be willing to provide accessor functions for the
information of the components? You could start with those you
currently need, i.e. for element declarations.

[1] http://www.w3.org/TR/xmlschema-1/#sic-schema


The xmlSchemaDump fonction uses this method, (and testSchemas uses
xmlSchemaDump) and with the following schema :

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";;>

  <xsd:element name="ELEMENTS">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="element" type="xsd:string" minOccurs="0"
maxOccurs="unbounded"/>

        <xsd:element name="element2" type="xsd:string" minOccurs="0"
maxOccurs="unbounded"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>

</xsd:schema>


- using libxml2-2.6.21 : 
testSchemas --debug test.xsd --noout


It gives :

Schemas: no name, no target namespace
Type: #CT1 [complex] content: [element]
  SEQUENCE
    ELEM 'element' min: 0 max: unbounded
    ELEM 'element2' min: 0 max: unbounded

Element (global): ELEMENTS
  min 0 max: 0
Element: element
  min 0 max: 0
  type: string ns http://www.w3.org/2001/XMLSchema
Element: element2
  min 0 max: 0

  type: string ns http://www.w3.org/2001/XMLSchema

- with libxml2-2.6.22 :
testSchemas --debug test.xsd --noout

It gives

Schemas: no name, no target namespace
Element (global): ELEMENTS
  min 0 max: 0

The local elements are not listed.

Uh, yes, we need to adjust this.

I tried to define ENABLE_NAMED_LOCALS (in xmlschemas.c) but it gave me the same result.

ENABLE_NAMED_LOCALS is just a left over, since we internally tried to
give anonymous components an internal name. I changed this to keep a
"name" field of NULL, due to the spec - and performance.

Is there a mean to retrieve all the element declarations ?

As mentioned above.

Regards,

Kasimier




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