Re: [xml] How can I get namespaces of schematypes ?



Hi,

Hewarth, Michael wrote:
Hi !

Thanxs a lot for adding targetnamespace that fast. It works fine for types. It would be nice, if it would 
work for subelems too. Take this schema for example:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="urn:bsp" xmlns:t="urn:bsp"
elementFormDefault="qualified" attributeFormDefault="unqualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"; >

        <xs:element name="baselem" type="t:mybase"/>

        <xs:complexType name="mybase">
                <xs:sequence id="baseseq">
                        <xs:element name="base1" type="xs:string"/>
                        <xs:element name="base2" type="xs:string"/>
                </xs:sequence>
        </xs:complexType>

</xs:schema>

I get the namespace of t:mybase - very fine. But if I look at the subtypes of t:mybase, I get name base1 and base2 but 
targetnamespace="". As workaround I take the namespace of mybase and write it in my wrapper class, but it 
would be nice to get it directly from the struct xmlSchemaTypePtr.

If you used testSchemas to look for the targetNamespace,
then the output was misleading, since it the element declaration
dump function was not yet adjusted to output the new targetNamespace
field.

Adding of the following to xmlSchemaElementDump:

if (elem->targetNamespace != NULL)
        fprintf(output, "namespace '%s' ", elem->targetNamespace);

results in the following debug output:

P:\libxml2-lab\builded\libxml2\lib>testschemas --debug test.xsd
Schemas: no name, urn:bsp
Type: mybase, complex element
  subtypes: #seq 1
Type: #seq 1, sequence element
  subtypes: base1 base2
Element : base2 namespace 'urn:bsp'
  type: string ns http://www.w3.org/2001/XMLSchema
Element global : baselem namespace 'urn:bsp'
  type: mybase ns urn:bsp
Element : base1 namespace 'urn:bsp'
  type: string ns http://www.w3.org/2001/XMLSchema

P:\libxml2-lab\builded\libxml2\lib>xmllint --version
xmllint: using libxml version 20617CVS2309
compiled with: FTP HTTP HTML C14N Catalog DocBook XPath XPointer XInclude Iconv MemDebug Unicode Regexps Automata Schemas

I used the current CVS HEAD for this - especially
"xmlschemas.c" rev. 1.92.
Here the targetNamespace of element declaration "base1" is "urn:bsp".
I'll commit the fix for the dump function soon (today).

I would not recommend using the structs to access the data. Try to use
accessor functions. If you have finished them, send them to this mailing
list with a subject like: "I give you some functions" :-)
The hope here, for the future is, that the multi-purpose structs can be
mapped more clearly to the schema components defined by the spec. But
maby Daniel again has one of this superb ideas how to do this in a
different, possibly simpler, manner.

I hope I find enough time to write some accessor functions in xmllib style. I have written a C++ Com 
Interface Wrapper for most common uses. I 'll work on xmlstyle accessor functions and use them in my Wrapper 
and send it to you, but time is short.

Thanks in advance!

By the way:
in libxslt/xsltwin32config.h there is:
/**
 * LIBXSLT_VERSION_EXTRA
 *
 * extra version information, used to show a CVS compilation
 */
#define LIBXML_VERSION_EXTRA "-CVS964"
And I get a compilation error (not with the standard build method, but I´m using a different build system, where I get xslt.c(50) : error C2146: syntax error : missing ';' before identifier 'LIBXSLT_VERSION_EXTRA'
xslt.c(50) : error C2144: syntax error : '<Unknown>' should be preceded by '<Unknown>'
xslt.c(50) : error C2144: syntax error : '<Unknown>' should be preceded by '<Unknown>'
xslt.c(50) : error C2143: syntax error : missing ';' before 'identifier'

Should it be:
/**
 * LIBXSLT_VERSION_EXTRA
 *
 * extra version information, used to show a CVS compilation
 */
#define LIBXSLT_VERSION_EXTRA "-CVS964"

If I use this it builds fine.

I recommend to put this on the XSLT mailing list; otherwise it might be
overseen by people who tend to skip XML Schemata related mails ;-)

Regards,

Kasimier




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