This is my XML file (sample):
[CODE]<?xml version = “1.0” encoding=”Windows-1252″ standalone=”yes”?>
<AuditFile xmlns=”urn:OECD:StandardAuditFile-Tax:PT_1.03_01″>
<Customer>
<CustomerID>ISO07060440644,401551083</CustomerID>
<AccountID>Desconhecido</AccountID>
<CustomerTaxID>501882</CustomerTaxID>
<CompanyName>BAberta</CompanyName>
<BillingAddress>
<AddressDetail>Edifing</AddressDetail>
<City>Praiso 1</City>
<PostalCode>4000-29</PostalCode>
<Country>PT</Country>
</BillingAddress>
<Telephone>220046</Telephone>
<SelfBillingIndicator>0</SelfBillingIndicator>
</Customer>
</AuditFile>
This is my PHP code, …
[code=php]
$xmlReader = new XMLReader();
$xmlReader->open($FileName);
$tag = ‘Customer’;
while($xmlReader->read()) {
while ($tag == $xmlReader->name) {
// since XMLReader doesn’t really supply us with much of a usable
// API, we can convert the current node to an instace of `SimpleXMLElement`
$elem = new SimpleXMLElement($xmlReader->readOuterXML());
var_dump($elem);
echo “<br>”;
// now use SimpleXMLElement as you normally would.
foreach ($elem->children() as $child) {
echo $child->getName(). ‘: ‘. $child;
if ($child->getName()==’CustomerID’) {$id=$child;}
if ($child->getName()==’CompanyName’) {$CN=$child;}
if ($child->getName()==’CustomerTaxID’) {$CTID=$child;}
if ($child->getName()==’BillingAddress’)
{
echo ” -> “;
// CANOT BROWSE THIS TAG —- HELP!!! It only works up to here.
foreach ($BillingAddress->children() as $child2) {
if ($child2->getName()==’AddressDetail’) { echo $child2;}
}
echo ” <- “;
}
}
echo “<br>”;
$xmlReader->next($tag);
}
}
Since the file is very big, I am using XMLREADER + SIMPLEXML to open the file and give me the output on screen.
A simple ECHO will do, since I will put the values in variables and output then on a HTML table.
The problem I have is that I get a 2 SimpleXMLElements because of the subtag BillingAddress.
How can I get the tags below the BillingAddress????