[Xml-compile] Adding namespaced attributes to elements
Drew Taylor
drew at drewtaylor.com
Mon Aug 18 12:16:48 BST 2008
Mark rightly noted this question should have been in a new thread, so
here goes.
This is an example of the element where I need a namedspaced attribute
added:
<Segment Apply="Included" ID="CELASSGS" xsi:type="SegmentInsuranceType">
<![CDATA[foo bar baz]]>
<Code Name="Code" Role="Reference" Value="xxx"/>
<Price Ref="PA" Value="100"/>
</Segment>
In my case there are only a few elements which need the attribute, so
a hook would probably suffice. A nicer way would be useful of
course. :-)
Drew
>> A new question: how can I specify a 'xsi:type="foo"' attribute on an
>> element? An example is: <Segment xsi:type="SegmentProductType">. I
>> tried passing " 'xsi:type' => 'foo' " in the data structure but it
>> was
>> ignored.
>
>
> On the moment, there are no helpers to achieve this. Probably, I
> should
> create an option to have these added. It will be implemented as an
> after-hook, which you can also make yourself:
>
> $schema->addHook(type => $mytype, after =>
> sub { my ($doc, $xml, $path, $val) = @_;
> $xml->setAttribute("xsi:type" => $mytype);
> $xml;
> });
>
> Unconvenient when you have many types which you want to make explicit.
> XML::Compile::SOAP::Encoding knows how to do it better.
>
> I have to think about a better solutions, although you should not need
> it when using schemas the usual way.
More information about the Xml-compile
mailing list