<div dir="ltr">Maybe I was a bit vague,to be understood<div><br></div><div>I have a schema (VMWare webservices, with urn:vim25 namespace) which have some elements defined as xsd:anyType</div><div><br></div><div>...</div><div><div>  &lt;complexType name=&quot;DynamicProperty&quot;&gt;</div><div>      &lt;sequence&gt;</div><div>         &lt;element name=&quot;name&quot; type=&quot;xsd:string&quot; /&gt;</div><div>         &lt;element name=&quot;val&quot; type=&quot;xsd:anyType&quot; /&gt;</div><div>      &lt;/sequence&gt;</div><div>   &lt;/complexType&gt;</div></div><div>...</div><div><div>&lt;element name=&quot;propSet&quot; type=&quot;vim25:DynamicProperty&quot; minOccurs=&quot;0&quot; maxOccurs=&quot;unbounded&quot; /&gt;</div></div><div><br></div><div>Inside XML documents I try to read the appropriate elements always have xsi:type associated with them.</div><div><br></div><div>...<br></div><div><div>        &lt;propSet&gt;</div><div>          &lt;name&gt;configStatus&lt;/name&gt;</div><div>          &lt;val xsi:type=&quot;ManagedEntityStatus&quot;&gt;green&lt;/val&gt;</div><div>        &lt;/propSet&gt;</div></div><div>...</div><div><br></div><div><div>When I read XML elements based on such schema, those elements (val above), are left untranslated and appears in the resulting structure </div><div>as original XML::LibXML elements. I understand this and do not expect XML::Compile to behave differently.</div></div><div><br></div><div><br></div><div>What I want is to translate those &quot;xsd:anyType&quot; elements manually, either via hook or by traversing the result structure</div><div>and compiling those untranslated elements with another call of a new reader.</div><div><br></div><div>Since all of these elements always come with a type I thought that would be nice to create a new reader for the type,</div><div>say &quot;{urn:vim25}ManagedEntityStatus&quot;.</div><div><br></div><div>my $reader = $xml_schema-&gt;compile(READER =&gt; &quot;{urn:vim25}ManagedEntityStatus&quot;);<br></div><div><br></div><div>and read the untranslated element with it:</div><div><br></div><div>$reader-&gt;($element)<br></div><div><br></div><div>with the meaning read the element, translate its content and attributes according to XML type, regardless of element name.</div><div>But to create such $reader is not possible.</div><div><br></div><div>So the only other way I can imagine is to:</div><div><br></div><div>1) add a new fake XML schema to my $xml_schema</div><div><br></div><div><div>&lt;xsd:schema xmlns:xsd=&quot;<a href="http://www.w3.org/2001/XMLSchema">http://www.w3.org/2001/XMLSchema</a>&quot; </div><div>    xmlns:tns=&quot;urn:myNonsenseSchema&quot; </div><div>    xmlns:orig=&quot;urn:vim25&quot;</div><div>    targetNamespace=&quot;urn:myNonsenseSchema&quot;</div><div>    elementFormDefault=&quot;qualified&quot;&gt;</div><div>&lt;xsd:element name=&quot;ManagedEntityStatus&quot; type=&quot;orig:ManagedEntityStatus&quot;/&gt;</div><div>&lt;/xsd:element&gt;</div></div><div><br></div><div>creating an element for the type.</div><div><br></div><div><div>2) Create a reader for this new element &quot;{urn:myNonsenseSchema}ManagedEntityStatus&quot;.</div></div><div><br></div><div>3) Create a new XML element with same content and attributes, but with different name.</div><div><br></div><div>i.e. turn</div><div><br></div><div> &lt;val xsi:type=&quot;ManagedEntityStatus&quot;&gt;green&lt;/val&gt;<br></div><div><br></div><div>into</div><div><br></div><div> &lt;newns:ManagedEntityStatus&gt;green&lt;/val&gt;<br></div><div><br></div><div>4) read the new element with the new reader</div><div><br></div><div><br></div><div>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?</div><div><br></div><div><br></div><div>Thanks for any comment</div><div><br></div><div><br></div><div>Roman Daniel</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div>, the values for such elements are left untranslated</div><div><br></div><div><br></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-11-05 0:16 GMT+01:00 Mark Overmeer <span dir="ltr">&lt;<a href="mailto:mark@overmeer.net" target="_blank">mark@overmeer.net</a>&gt;</span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">* Roman Daniel (<a href="mailto:roman.daniel@davosro.cz">roman.daniel@davosro.cz</a>) [151104 16:41]:<br>
<span class="">&gt; Is it possible to create a reader (hook) respecting the xsi:type blindly,<br>
&gt; i.e. without the hierarchy of xsi:type types? I have a XML schema where<br>
&gt; some elements in schema are xsd:any, while the documents contains xsi:type<br>
&gt; for such elements.<br>
<br>
</span>&quot;any&quot; elements and xsi:type are different things.  With &lt;any&gt;, you must<br>
expect any kind of element (actually, the documentation tells you what<br>
the options are)  Those elements are defined somewhere in some schema.<br>
<br>
With xsi:type you can replace the type of an element with an extension<br>
type.  It can appear anywhere in your message.  Horrible.<br>
<span class=""><br>
&gt; I thought I can create a hook for an element with xsi:type attribute, but I<br>
&gt; found no way to compile a reader for the XML schema type - only for the<br>
&gt; elements. Is it really impossible?<br>
<br>
</span>XML::Compile is a compiler... so: it needs to know beforehand what may<br>
appear where.  There are a few ways how to do that, probably<br>
   $schema-&gt;addXsiType is the easiest for you.  Find the base-type<br>
which is used in the element definition, and then from the docs<br>
which xsi:type can be expected there and list them.  Or try AUTO.<br>
<span class="HOEnZb"><font color="#888888">--<br>
success,<br>
<br>
               MarkOv<br>
<br>
------------------------------------------------------------------------<br>
       Mark Overmeer MSc                                MARKOV Solutions<br>
       Mark@Overmeer.net                          <a href="mailto:solutions@overmeer.net">solutions@overmeer.net</a><br>
<a href="http://Mark.Overmeer.net" rel="noreferrer" target="_blank">http://Mark.Overmeer.net</a>                   <a href="http://solutions.overmeer.net" rel="noreferrer" target="_blank">http://solutions.overmeer.net</a><br>
<br>
</font></span></blockquote></div><br></div>