PHP SimpleXML Optional Child Nodes



I'm trying to separate my child nodes according their children but I can't figure out how to validate whether the node has a value.


Here's my XML:



<?xml version="1.0"?>
<testcase>
<steps>
<step id="one">
<command>gettitle</command>
</step>
<step id="two">
<command>click</command>
<parameter>id=searchByAddressSubmit</parameter>
</step>
</steps>
</testcase>


Here's my Code:



$testcase = new SimpleXMLElement($xml);
foreach($testcase->steps->step as $step) {
echo $step->parameter;
echo $step->command;
if(empty($step->parameter)) {
echo $step>command;
}
}


The result should be:



gettitle


I've tried empty(), array_key_exists(), and is_null() but nothing seems to pick a missing value. Any ideas?


No comments:

Post a Comment