I am learning how to use Perl as a test automation tool for a Java web service and run problems creating xml requests from pastor-created modules. The problem is that when you include a type that extends from the required type for an element, the xsi: type is not included in the generated xml string. Say, for example, I want to generate the following xml request from the modules that XML :: Pastor generates from my xsd:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<PromptAnswersRequest xmlns="http://mycompany.com/api">
<Uri>/some/url</Uri>
<User ref="1"/>
<PromptAnswers>
<PromptAnswer xsi:type="textPromptAnswer" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Prompt ref="2"/>
<Children>
<PromptAnswer xsi:type="choicePromptAnswer">
<Prompt ref="1"/>
<Choice ref="2"/>
</PromptAnswer>
</Children>
<Value>totally</Value>
</PromptAnswer>
</PromptAnswers>
</PromptAnswersRequest>
I am currently getting the following:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<PromptAnswersRequest xmlns="http://mycompany.com/api">
<Uri>/some/url</Uri>
<User ref="1"/>
<PromptAnswers>
<PromptAnswer>
<Prompt ref="2"/>
<Children>
<PromptAnswer>
<Prompt ref="1"/>
<Choice ref="2"/>
</PromptAnswer>
</Children>
<Value>totally</Value>
</PromptAnswer>
</PromptAnswers>
</PromptAnswersRequest>
Here are some relavent snippets from xsd:
<xs:complexType name="request">
<xs:sequence>
<xs:element name="Uri" type="xs:anyURI"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="promptAnswersRequest">
<xs:complexContent>
<xs:extension base="api:request">
<xs:sequence>
<xs:element name="User" type="api:ref"/>
<xs:element name="PromptAnswers" type="api:promptAnswerList"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="promptAnswerList">
<xs:sequence>
<xs:element name="PromptAnswer" type="api:promptAnswer" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="promptAnswer" abstract="true">
<xs:sequence>
<xs:element name="Prompt" type="api:ref"/>
<xs:element name="Children" type="api:promptAnswerList" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="textPromptAnswer">
<xs:complexContent>
<xs:extension base="promptAnswer">
<xs:sequence>
<xs:element name="Value" type="api:nonEmptyString" minOccurs="0"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
And here are some of the parts of the script:
my $promptAnswerList = new My::API::Type::promptAnswerList;
my @promptAnswers;
my $promptAnswerList2 = new My::API::Type::promptAnswerList;
my @textPromptAnswerChildren;
my $textPromptAnswer = new My::API::Type::textPromptAnswer;
my $textPromptAnswerRef = new My::API::Type::ref;
$textPromptAnswerRef->ref('2');
$textPromptAnswer->Prompt($textPromptAnswerRef);
my $choicePromptAnswer = new My::API::Type::choicePromptAnswer;
my $choicePromptAnswerPromptRef = new My::API::Type::ref;
my $choicePromptAnswerChoiceRef = new My::API::Type::ref;
$choicePromptAnswerPromptRef->ref('1');
$choicePromptAnswerChoiceRef->ref('2');
$choicePromptAnswer->Prompt($choicePromptAnswerPromptRef);
$choicePromptAnswer->Choice($choicePromptAnswerChoiceRef);
push(@textPromptAnswerChildren, $choicePromptAnswer);
$promptAnswerList2->PromptAnswer(@textPromptAnswerChildren);
$textPromptAnswer->Children($promptAnswerList2);
$textPromptAnswer->Value('totally');
push(@promptAnswers, $textPromptAnswer);
, - XML:: Pastor, , - , . , XML:: Pastor, , , , - - , !