PHP Parsing XML



i am having some problem with parsing XML.


What i am doing: I am spliting 1 XML to many and also editing few things for new one. And it works!!


Where is problem: After Parsing not all parts are same, to be more specifc in some of them are just 2 Labor Rate Details, in another there can be 5.:


So some looks like:



<LaborRateList>
<LaborRateDetail>
<Role>Labor</Role>
<Category>1</Category>
<Rate Cur="CZK" Unit="h" MinValue="0" MaxValue="0">250.0</Rate>
</LaborRateDetail>
<LaborRateDetail>
<Role>Paint</Role>
<Category>2</Category>
<Rate Cur="CZK" Unit="h" MinValue="0" MaxValue="0">350.0</Rate>
</LaborRateDetail>
</LaborRateList>


And another:



<LaborRateList>
<LaborRateDetail>
<Role>Labor</Role>
<Category>1</Category>
<Rate Cur="CZK" Unit="h" MinValue="0" MaxValue="0">250.0</Rate>
</LaborRateDetail>
<LaborRateDetail>
<Role>Labor</Role>
<Category>1</Category>
<Rate Cur="CZK" Unit="h" MinValue="0" MaxValue="0">250.0</Rate>
</LaborRateDetail>
<LaborRateDetail>
<Role>Labor</Role>
<Category>1</Category>
<Rate Cur="CZK" Unit="h" MinValue="0" MaxValue="0">250.0</Rate>
</LaborRateDetail>
<LaborRateDetail>
<Role>Labor</Role>
<Category>1</Category>
<Rate Cur="CZK" Unit="h" MinValue="0" MaxValue="0">250.0</Rate>
</LaborRateDetail>
<LaborRateDetail>
<Role>Paint</Role>
<Category>2</Category>
<Rate Cur="CZK" Unit="h" MinValue="0" MaxValue="0">350.0</Rate>
</LaborRateDetail>
</LaborRateList>


i was trying to find out how to not insert anything if there is no more labor rates. What i try was check if there is anything in variabile and if not write nothing so my code looks like:



//RATE3 PART
var_dump($value->Contract->LaborRateList->LaborRateDetail[2]->Role);
if ($value->Contract->LaborRateList->LaborRateDetail[2]->Role == 0)
//SOME CODE HERE


But i am getting error:



Notice: Trying to get property of non-object in C:\xampp\htdocs\xampp\provisioning\index.php on line 23
NULL
Notice: Trying to get property of non-object in C:\xampp\htdocs\xampp\provisioning\index.php on line 24


Can somebody help me to fix it?


No comments:

Post a Comment