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

Roman Daniel roman.daniel at davosro.cz
Sun Nov 22 19:07:35 GMT 2015


Maybe I was a bit vague,to be understood

I have a schema (VMWare webservices, with urn:vim25 namespace) which have
some elements defined as xsd:anyType

...
  <complexType name="DynamicProperty">
      <sequence>
         <element name="name" type="xsd:string" />
         <element name="val" type="xsd:anyType" />
      </sequence>
   </complexType>
...
<element name="propSet" type="vim25:DynamicProperty" minOccurs="0"
maxOccurs="unbounded" />

Inside XML documents I try to read the appropriate elements always have
xsi:type associated with them.

...
        <propSet>
          <name>configStatus</name>
          <val xsi:type="ManagedEntityStatus">green</val>
        </propSet>
...

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.


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.

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");

and read the untranslated element with it:

$reader->($element)

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.

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.

2) Create a reader for this new element
"{urn:myNonsenseSchema}ManagedEntityStatus".

3) Create a new XML element with same content and attributes, but with
different name.

i.e. turn

 <val xsi:type="ManagedEntityStatus">green</val>

into

 <newns:ManagedEntityStatus>green</val>

4) read the new element with the new reader


Which I think is possible, but very cumbersome. Am I understood now? Is
there really no other way how to read any element (just the top one) with
reader based on XML type?


Thanks for any comment


Roman Daniel












, the values for such elements are left untranslated





2015-11-05 0:16 GMT+01:00 Mark Overmeer <mark at overmeer.net>:

> * Roman Daniel (roman.daniel at davosro.cz) [151104 16:41]:
> > Is it possible to create a reader (hook) respecting the xsi:type blindly,
> > i.e. without the hierarchy of xsi:type types? I have a XML schema where
> > some elements in schema are xsd:any, while the documents contains
> xsi:type
> > for such elements.
>
> "any" elements and xsi:type are different things.  With <any>, you must
> expect any kind of element (actually, the documentation tells you what
> the options are)  Those elements are defined somewhere in some schema.
>
> With xsi:type you can replace the type of an element with an extension
> type.  It can appear anywhere in your message.  Horrible.
>
> > I thought I can create a hook for an element with xsi:type attribute,
> but I
> > found no way to compile a reader for the XML schema type - only for the
> > elements. Is it really impossible?
>
> XML::Compile is a compiler... so: it needs to know beforehand what may
> appear where.  There are a few ways how to do that, probably
>    $schema->addXsiType is the easiest for you.  Find the base-type
> which is used in the element definition, and then from the docs
> which xsi:type can be expected there and list them.  Or try AUTO.
> --
> success,
>
>                MarkOv
>
> ------------------------------------------------------------------------
>        Mark Overmeer MSc                                MARKOV Solutions
>        Mark at Overmeer.net                          solutions at overmeer.net
> http://Mark.Overmeer.net                   http://solutions.overmeer.net
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.scsys.co.uk/pipermail/xml-compile/attachments/20151122/e0c95e75/attachment.htm>


More information about the Xml-compile mailing list