[xsd-users] Attempting to access attribute xml:base.

Boris Kolpackov boris at codesynthesis.com
Sat Dec 30 12:52:34 EST 2006


Hi Jeroen,


Jeroen N. Witmond <jnw at xs4all.nl> writes:

> Thanks, I've got this to work in a test program, but I'm confused about
> the code generated for xml.xsd. I used 'xsd cxx-tree --namespace-map
> http://www.w3.org/XML/1998/namespace=XmlNamespace xml.xsd' and see that
> the generated .cxx file does not contain any executable code, nor does the
> generated .hxx file declare anything in namespace XmlNamespace.  Instead
> all code related to xml:base is in the files generated from my own .xsd
> file.

xml.xsd defines four global attributes and an attribute group. Those are
meant to be used via the ref="" attribute. As a result, there is nothing
being generated for these constructs where they are defined (xml.xsd),
only where they are used (your schema). XSD does not (yet) analyze the
schema to detect such a (presumably rare) case where there is nothing
useful being generated. So you still need to translate xml.xsd since
there will be #include "xml.hxx" directives present in the code generated
from your schema.


> > If you want to allow say xml:base in all types in your schema then
> > you may want to create a base type which includes only that attribute
> > and then inherit all other types from it.
>
> Unfortunately, I need to be able to access xml:base in code generated from
> schemas I do not author, where the use of xml:base is covered by a
> '<xs:anyAttribute namespace="##other"/>'.  So, instead of using a base
> type in XML, I would need a base class in C++.  And unless I've missed
> something, there is no way to tell xsd to generate its classes ': public
> XmlNamespace' (for instance, where XmlNamespace is a class that implements
> access to xml:base.).

There are a number of ways you can implement this (in the order of
increasing sophistication):


1. Use DOM association. You can pass the xml_schema::flags::keep_dom flag
   to one of the parsing functions which will result in the DOM nodes
   corresponding to the tree nodes being accessible via the _node()
   function. See Section 3.2, "Flags and Properties" of the C++/Tree
   Mapping Manual[1] as well as 'mixed' example for more information.
   Using the DOM API you can check for presence of the xml:base attribute.


2. You can do pretty much what you've described above by customizing the
   types that have <xs:anyAttribute namespace="##other"/> and check/extract
   the xml:base attribute in the constructor. See the C++/Tree Mapping
   Customization Guide[2] as well as the examples in the custom/ directory
   for details.


3. This is a variation of (2), for cases where you have a lot of unrelated
   types that all allow for <xs:anyAttribute namespace="##other"/>. In this
   case you may want to customize the xml_schema::type class which
   corresponds to XML Schema anyType and is a base for every generated
   types. You can customize xml_schema::type by inheriting from the
   original and checking for xml::base in the constructor. Again, see the
   C++/Tree Mapping Customization Guide[2] and examples for details.


[1] http://www.codesynthesis.com/projects/xsd/documentation/cxx/tree/manual/#3.2

[2] http://wiki.codesynthesis.com/Tree/Customization_guide


hth,
-boris

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 652 bytes
Desc: Digital signature
Url : http://codesynthesis.com/pipermail/xsd-users/attachments/20061230/a1709c5a/attachment.pgp


More information about the xsd-users mailing list