Instantiate the classes (and our mock responder.)
$SoapNodeUtilities = new SoapNodeUtilities();
$MockSoapData = new MockSoapData();
$SoapToArray = new SoapToArray($MockSoapData->mockXmlResponse(), LIBXML_NOCDATA);
$data_arr = $SoapToArray->toArray();
$response = htmlentities($MockSoapData->mockXmlResponse());
Given this SOAP response,
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<SessionResponse xmlns="http://example.com/sessions">
<SessionResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Result xmlns="http://example.com/accounts" xmlns:b="example.com/user">
<b:Success>true</b:Success>
<b:ResultInfo>
<b:ResultInfo>
<b:Code>200</b:Code>
<b:Description>Registered user was found.</b:Description>
<b:Field>UserId</b:Field>
<b:ListItemId i:nil="true"/>
<b:ResultStatus>SUCCESS</b:ResultStatus>
</b:ResultInfo>
<b:ResultInfo>
<b:Code>200</b:Code>
<b:Description>Registered user account is current.</b:Description>
<b:Field>UserStatus</b:Field>
<b:ListItemId i:nil="true"/>
<b:ResultStatus>SUCCESS</b:ResultStatus>
</b:ResultInfo>
<b:ResultInfo>
<b:Code>200</b:Code>
<b:Description>User security updates complete.</b:Description>
<b:Field>UserHasUpdated</b:Field>
<b:ResultStatus>SUCCESS</b:ResultStatus>
</b:ResultInfo>
</b:ResultInfo>
</Result>
<UserComments xmlns="http://example.com/comments" xmlns:a="example.com/comments">
<a:CommentContent>
<a:CommentDate>202101015</a:CommentDate>
<a:CommentBy>
<a:CommentorName>John Doe</a:CommentorName>
<a:CommentorDepartment>Human Resources</a:CommentorDepartment>
<a:CommentorPosition>Manager</a:CommentorPosition>
<a:CommentorComment>Mary is a hard worker.</a:CommentorComment>
</a:CommentBy>
</a:CommentContent>
</UserComments>
</SessionResult>
</SessionResponse>
</s:Body>
</s:Envelope>
Use SoapNodeUtilities to return the Success node.
echo $MockSoapData->outputDataPreTags($SoapNodeUtilities->findNode('Success', $data_arr));
true
Get a group of nodes with the same names and namespaces.
echo $MockSoapData->outputDataPreTags($SoapNodeUtilities->findNode('ResultInfo', $data_arr));
Array
(
[ResultInfo] => Array
(
[0] => Array
(
[Code] => 200
[Description] => Registered user was found.
[Field] => UserId
[ListItemId] =>
[ResultStatus] => SUCCESS
)
[1] => Array
(
[Code] => 200
[Description] => Registered user account is current.
[Field] => UserStatus
[ListItemId] =>
[ResultStatus] => SUCCESS
)
[2] => Array
(
[Code] => 200
[Description] => User security updates complete.
[Field] => UserHasUpdated
[ResultStatus] => SUCCESS
)
)
)
Get just the descriptions of the same nodes.
echo $MockSoapData->outputDataPreTags($SoapNodeUtilities->findNodes('Description', $data_arr));
Array
(
[0] => Registered user was found.
[1] => Registered user account is current.
[2] => User security updates complete.
)
Get a more deeply nested comment node.
echo $MockSoapData->outputDataPreTags($SoapNodeUtilities->findNode('CommentorComment', $data_arr));
Mary is a hard worker.
Get all the commentor node information.
echo $MockSoapData->outputDataPreTags($SoapNodeUtilities->findNode('CommentContent', $data_arr));
Array
(
[CommentDate] => 202101015
[CommentBy] => Array
(
[CommentorName] => John Doe
[CommentorDepartment] => Human Resources
[CommentorPosition] => Manager
[CommentorComment] => Mary is a hard worker.
)
)
Output the whole array returned from SoapToArray without using SoapNodeUtilities.
echo $MockSoapData->outputDataPreTags($data_arr);
Array
(
[Body] => Array
(
[SessionResponse] => Array
(
[0] => Array
(
[SessionResult] => Array
(
[0] => Array
(
[Result] => Array
(
[Success] => true
[ResultInfo] => Array
(
[ResultInfo] => Array
(
[0] => Array
(
[Code] => 200
[Description] => Registered user was found.
[Field] => UserId
[ListItemId] =>
[ResultStatus] => SUCCESS
)
[1] => Array
(
[Code] => 200
[Description] => Registered user account is current.
[Field] => UserStatus
[ListItemId] =>
[ResultStatus] => SUCCESS
)
[2] => Array
(
[Code] => 200
[Description] => User security updates complete.
[Field] => UserHasUpdated
[ResultStatus] => SUCCESS
)
)
)
)
[UserComments] => Array
(
[CommentContent] => Array
(
[CommentDate] => 202101015
[CommentBy] => Array
(
[CommentorName] => John Doe
[CommentorDepartment] => Human Resources
[CommentorPosition] => Manager
[CommentorComment] => Mary is a hard worker.
)
)
)
)
)
)
)
)
)