Hi guys,
Is there an easy way to go through an array using XML data...
My XML file looks like this.
<standardrates>
<standardrate>
<ratecode></ratecode>
<codetype>0</codetype>
<costtype>0</costtype>
<desc>Plumbrate Library</desc>
<units></units>
<quantity>0</quantity>
<cost>0</cost>
<standardrate>
<ratecode></ratecode>
<codetype>2</codetype>
<costtype>0</costtype>
<desc>SANITARY PLUMBING</desc>
<units></units>
<quantity>0</quantity>
<cost>0</cost>
<standardrate>
<ratecode></ratecode>
<codetype>0</codetype>
<costtype>0</costtype>
<desc>SANITARY PLUMBING (FIXTURES)</desc>
<units></units>
<quantity>0</quantity>
<cost>0</cost>
<standardrate>
<ratecode>H00100</ratecode>
<codetype>2</codetype>
<costtype>0</costtype>
<desc>CAROMA MONARCH CLOSE COUPLE TOILET SUITE</desc>
<units></units>
<quantity>0</quantity>
<cost>1574</cost>
<standardrate>
<ratecode>061568</ratecode>
<suppliercode>TRADELINK</suppliercode>
<codetype>1</codetype>
<costtype>Material</costtype>
<desc>SPA KIRSTY CNR 6 GLD JET TP 1300</desc>
<units>EA</units>
<quantity>1</quantity>
<cost>1322.1</cost>
</standardrate>
<standardrate>
<ratecode>030837</ratecode>
<suppliercode>TRADELINK</suppliercode>
<codetype>1</codetype>
<costtype>Material</costtype>
<desc>MORTAR DRYMIX 30KG</desc>
<units>EA</units>
<quantity>0.25</quantity>
<cost>10.07</cost>
</standardrate>
<standardrate>
<ratecode>030262</ratecode>
<suppliercode>TRADELINK</suppliercode>
<codetype>1</codetype>
<costtype>Material</costtype>
<desc>SEALANT SILICON ANTIFUNGAL WHT</desc>
<units>EA</units>
<quantity>0.25</quantity>
<cost>6.36</cost>
</standardrate>
<standardrate>
<ratecode>027979</ratecode>
<suppliercode>TRADELINK</suppliercode>
<codetype>1</codetype>
<costtype>Material</costtype>
<desc>SCREWS CSK WOOD BRS SLOT 80MM X 12G (EACH)</desc>
<units>EA</units>
<quantity>4.4</quantity>
<cost>0.79</cost>
</standardrate>
<standardrate>
<ratecode>029841</ratecode>
<suppliercode>TRADELINK</suppliercode>
<codetype>1</codetype>
<costtype>Material</costtype>
<desc>ANCHOR SCREW GRN 40MM(PER 25)</desc>
<units>PK</units>
<quantity>0.2</quantity>
<cost>2.03</cost>
</standardrate>
<standardrate>
<ratecode>063641</ratecode>
<suppliercode>TRADELINK</suppliercode>
<codetype>1</codetype>
<costtype>Material</costtype>
<desc>SCREW GUARD FOR TOILET PAN (EACH)</desc>
<units>EA</units>
<quantity>4.4</quantity>
<cost>0.08</cost>
</standardrate>
<standardrate>
<ratecode>027965</ratecode>
<suppliercode>TRADELINK</suppliercode>
<codetype>1</codetype>
<costtype>Material</costtype>
<desc>SCREWS CSK WOOD BRS SLOT 40MM X 10G (EACH)</desc>
<units>EA</units>
<quantity>3.3</quantity>
<cost>0.39</cost>
</standardrate>
<standardrate>
<ratecode>029833</ratecode>
<suppliercode>TRADELINK</suppliercode>
<codetype>1</codetype>
<costtype>Material</costtype>
<desc>ANCHOR SCREW BLU 40MM(PER 25)</desc>
<units>PK</units>
<quantity>0.15</quantity>
<cost>1.74</cost>
</standardrate>
<standardrate>
<ratecode>RATE01</ratecode>
<suppliercode>LABOUR</suppliercode>
<codetype>1</codetype>
<costtype>Labour</costtype>
<desc>ESTIMATING LABOUR RATE</desc>
<units>PER HOUR</units>
<quantity>4.4</quantity>
<cost>55</cost>
</standardrate>
</standardrate>
<standardrate>
<ratecode>H00102</ratecode>
<codetype>2</codetype>
<costtype>0</costtype>
<desc>CAROMA LEDA VICEROY TOILET SUITE</desc>
<units></units>
<quantity>0</quantity>
<cost>1452.2</cost>
<standardrate>
<ratecode>062069</ratecode>
<suppliercode>TRADELINK</suppliercode>
<codetype>1</codetype>
<costtype>Material</costtype>
<desc>AIR SYSTEM/DUAL (12 ADJ INJECT) GLD ***ADD*** LA</desc>
<units>EA</units>
<quantity>1</quantity>
<cost>825</cost>
</standardrate>
<standardrate>
<ratecode>060943</ratecode>
<suppliercode>TRADELINK</suppliercode>
<codetype>1</codetype>
<costtype>Material</costtype>
<desc>BASIN STAR VANITY ACRYLIC 1TH W/- BRK APR</desc>
<units>EA</units>
<quantity>1</quantity>
<cost>38.84</cost>
</standardrate>
<standardrate>
<ratecode>064364</ratecode>
<suppliercode>TRADELINK</suppliercode>
<codetype>1</codetype>
<costtype>Material</costtype>
<desc>TOILET SEAT SCANDINAVIA DBL FLAP STD HINGE WHT</desc>
<units>EA</units>
<quantity>1</quantity>
<cost>282.74</cost>
</standardrate>
<standardrate>
<ratecode>062249</ratecode>
<suppliercode>TRADELINK</suppliercode>
<codetype>1</codetype>
<costtype>Material</costtype>
<desc>BRACKET PAN SUIT LEDA 2000 D160 CAROMA 687160</desc>
<units>EA</units>
<quantity>1</quantity>
<cost>55.07</cost>
</standardrate>
<standardrate>
<ratecode>030837</ratecode>
<suppliercode>TRADELINK</suppliercode>
<codetype>1</codetype>
<costtype>Material</costtype>
<desc>MORTAR DRYMIX 30KG</desc>
<units>EA</units>
<quantity>0.25</quantity>
<cost>10.07</cost>
</standardrate>
<standardrate>
<ratecode>030262</ratecode>
<suppliercode>TRADELINK</suppliercode>
<codetype>1</codetype>
<costtype>Material</costtype>
<desc>SEALANT SILICON ANTIFUNGAL WHT</desc>
<units>EA</units>
<quantity>0.25</quantity>
<cost>6.36</cost>
</standardrate>
<standardrate>
<ratecode>027979</ratecode>
<suppliercode>TRADELINK</suppliercode>
<codetype>1</codetype>
<costtype>Material</costtype>
<desc>SCREWS CSK WOOD BRS SLOT 80MM X 12G (EACH)</desc>
<units>EA</units>
<quantity>4.4</quantity>
<cost>0.79</cost>
</standardrate>
<standardrate>
<ratecode>063641</ratecode>
<suppliercode>TRADELINK</suppliercode>
<codetype>1</codetype>
<costtype>Material</costtype>
<desc>SCREW GUARD FOR TOILET PAN (EACH)</desc>
<units>EA</units>
<quantity>4.4</quantity>
<cost>0.08</cost>
</standardrate>
<standardrate>
<ratecode>029841</ratecode>
<suppliercode>TRADELINK</suppliercode>
<codetype>1</codetype>
<costtype>Material</costtype>
<desc>ANCHOR SCREW GRN 40MM(PER 25)</desc>
<units>PK</units>
<quantity>0.3</quantity>
<cost>2.03</cost>
</standardrate>
<standardrate>
<ratecode>RATE01</ratecode>
<suppliercode>LABOUR</suppliercode>
<codetype>1</codetype>
<costtype>Labour</costtype>
<desc>ESTIMATING LABOUR RATE</desc>
<units>PER HOUR</units>
<quantity>4.4</quantity>
<cost>55</cost>
</standardrate>
</standardrate>
and my php looks like this
$xml = "";
$f = fopen( $filename, 'r' );
while( $data = fread( $f, 4096 ) ) { $xml .= $data; }
fclose( $f );
preg_match_all( "/\<standardrate\>(.*?)\<\/standardrate\>/s", $xml, $rateblocks );
preg_match_all( "/\<codetype\>(.*?)\<\/codetype\>/s", $xml, $codetype );
foreach( $rateblocks[1] as $key => $rateValue)
{
$codetypeValue = $codetype[$key];
echo "<br><br>Code Type = $codetypeValue<br>";
}
All it is returning is Code Type = Array
What I am essentially trying to do just concatenate the first and second <standardrates> tag names to create one $category_name variable, then create a variable called $name for the third (it will then continue to loop through, I may then get more level one, two and three standard rates)
Thanks heaps in advance.