[Xml-compile] Reading (hooks) according to xsi:type without xsi:type hierarchy

Mark Overmeer mark at overmeer.net
Mon Nov 23 08:55:51 GMT 2015


Hi Roman,

* Roman Daniel (roman.daniel at davosro.cz) [151122 19:08]:
> I have a schema (VMWare webservices, with urn:vim25 namespace) which have
> some elements defined as xsd:anyType

>          <element name="val" type="xsd:anyType" />
>          <val xsi:type="ManagedEntityStatus">green</val>

The ugliness of anyType combined with the ugliness of xsi:type!  Argggg!
Haven't seen that before.

> When I read XML elements based on such schema, those elements (val above),
> are left untranslated and appears in the resulting structure
> as original XML::LibXML elements. I understand this and do not expect
> XML::Compile to behave differently.

That's the default behavior of the anyType handler, yes.

> What I want is to translate those "xsd:anyType" elements manually, either
> via hook or by traversing the result structure and compiling those
> untranslated elements with another call of a new reader.

There exists logic to decode <any> elements, but not for anyType elements.
Yes, a hook will probably work.

> Since all of these elements always come with a type I thought that would be
> nice to create a new reader for the type,
> say "{urn:vim25}ManagedEntityStatus".
> 
> my $reader = $xml_schema->compile(READER =>
> "{urn:vim25}ManagedEntityStatus");

Why are you not using
    my $r = $schema->reader("{urn:vim25}ManagedEntityStatus");

or  $schema->addPrefixes(vm => 'urn:vim25');
    my $r = $schema->reader("vm:ManagedEntityStatus");

It will cash the compiled handlers for you.

> with the meaning read the element, translate its content and attributes
> according to XML type, regardless of element name.
> But to create such $reader is not possible.

Of course it is possible... whether it is supported is a different
question ;-)

> So the only other way I can imagine is to:
> 
> 1) add a new fake XML schema to my $xml_schema
> 
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>     xmlns:tns="urn:myNonsenseSchema"
>     xmlns:orig="urn:vim25"
>     targetNamespace="urn:myNonsenseSchema"
>     elementFormDefault="qualified">
> <xsd:element name="ManagedEntityStatus" type="orig:ManagedEntityStatus"/>
> </xsd:element>
> 
> creating an element for the type.

This is the trick used by $schema->compileType
Don't hessitate to ask for more details.
-- 
Regards,

               MarkOv

------------------------------------------------------------------------
       Mark Overmeer MSc                                MARKOV Solutions
       Mark at Overmeer.net                          solutions at overmeer.net
http://Mark.Overmeer.net                   http://solutions.overmeer.net




More information about the Xml-compile mailing list