<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> <complexType name="DynamicProperty"></div><div> <sequence></div><div> <element name="name" type="xsd:string" /></div><div> <element name="val" type="xsd:anyType" /></div><div> </sequence></div><div> </complexType></div></div><div>...</div><div><div><element name="propSet" type="vim25:DynamicProperty" minOccurs="0" maxOccurs="unbounded" /></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> <propSet></div><div> <name>configStatus</name></div><div> <val xsi:type="ManagedEntityStatus">green</val></div><div> </propSet></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 "xsd:anyType" 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 "{urn:vim25}ManagedEntityStatus".</div><div><br></div><div>my $reader = $xml_schema->compile(READER => "{urn:vim25}ManagedEntityStatus");<br></div><div><br></div><div>and read the untranslated element with it:</div><div><br></div><div>$reader->($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><xsd:schema xmlns:xsd="<a href="http://www.w3.org/2001/XMLSchema">http://www.w3.org/2001/XMLSchema</a>" </div><div> xmlns:tns="urn:myNonsenseSchema" </div><div> xmlns:orig="urn:vim25"</div><div> targetNamespace="urn:myNonsenseSchema"</div><div> elementFormDefault="qualified"></div><div><xsd:element name="ManagedEntityStatus" type="orig:ManagedEntityStatus"/></div><div></xsd:element></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 "{urn:myNonsenseSchema}ManagedEntityStatus".</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> <val xsi:type="ManagedEntityStatus">green</val><br></div><div><br></div><div>into</div><div><br></div><div> <newns:ManagedEntityStatus>green</val><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"><<a href="mailto:mark@overmeer.net" target="_blank">mark@overmeer.net</a>></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="">> Is it possible to create a reader (hook) respecting the xsi:type blindly,<br>
> i.e. without the hierarchy of xsi:type types? I have a XML schema where<br>
> some elements in schema are xsd:any, while the documents contains xsi:type<br>
> for such elements.<br>
<br>
</span>"any" elements and xsi:type are different things. With <any>, 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>
> I thought I can create a hook for an element with xsi:type attribute, but I<br>
> found no way to compile a reader for the XML schema type - only for the<br>
> 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->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>