Buenas noches, tengo un problema; tengo que armar un script para 'leer' un archivo xml y guardarlo en una base de datos.
Consigo leer el xml salvo un tag que dice product last updated.
como se hace?
Les pongo una parte del xml y lo que estoy haciendo para ver en principio el xml.
Gracias.
Código PHP:
<?xml version="1.0" encoding="UTF-8"?><data version="2">
<products>
<product lastUpdated="2011-09-30 07:41:41">
<id>22185557</id>
<name>Discover&#174; Mix Tape Student Card</name>
<description><ul><li>0% intro APR on purchases for 9 months, then the variable standard purchase APR of 13.99% - 20.99%*</li><li>5% Cashback Bonus&reg;* in categories that change like travel, gas, groceries, restaurants, home improvement stores and more. Limitations apply*</li><li>Up to 20% Cashback Bonus at popular retailers when you shop online through Discover.com</li><li>Up to 1% unlimited Cashback Bonus on everything else you buy</li><li>$0 Fraud Liability plus mobile and email fraud alert options</li><li>Great rewards with no annual fee, no rewards redemption fee, and no additional card fee</li></ul></description>
<shortDescription>Apply for the Discover&#174; Mix Tape Student credit card by filling out a secure online application.</shortDescription>
<imagePath>__MixTape_Card.gif</imagePath>
<url>http://oc.cardsynergy.com/t/?aid=999999&c=22185557</url>
<introApr>0% on Purchases*</introApr>
<q_introApr>0.00</q_introApr>
<introAprPeriod>9 months*</introAprPeriod>
<q_introAprPeriod>9</q_introAprPeriod>
<regularApr>13.99%-20.99% (V)*</regularApr>
<q_regularApr>13.99</q_regularApr>
<annualFee>None*</annualFee>
<q_annualFee>0.00</q_annualFee>
<creditNeeded>Fair Credit*</creditNeeded>
<q_creditNeeded>2</q_creditNeeded>
<balanceTransfers>N/A*</balanceTransfers>
<q_balanceTransfers>0</q_balanceTransfers>
<transaction_fee_pin>$0*</transaction_fee_pin>
<q_transaction_fee_pin>0</q_transaction_fee_pin>
<transaction_fee_signature>$0*</transaction_fee_signature>
<q_transaction_fee_signature>0</q_transaction_fee_signature>
<load_fee>$0*</load_fee>
<q_load_fee>0</q_load_fee>
<atm_fee>$0*</atm_fee>
<q_atm_fee>0</q_atm_fee>
<activation_fee>$0*</activation_fee>
<q_activation_fee>0</q_activation_fee>
<balanceTransferIntroApr>0.00*</balanceTransferIntroApr>
<q_balanceTransferIntroApr>0</q_balanceTransferIntroApr>
<balanceTransferIntroAprPeriod>N/A*</balanceTransferIntroAprPeriod>
<q_balanceTransferIntroAprPeriod>999</q_balanceTransferIntroAprPeriod>
<balanceTransferGoToRate>N/A*</balanceTransferGoToRate>
<q_balanceTransferGoToRate>999</q_balanceTransferGoToRate>
<cashAdvanceGoToRate>N/A*</cashAdvanceGoToRate>
<q_cashAdvanceGoToRate>999</q_cashAdvanceGoToRate>
<penaltyGoToRate>18.990 % - 29.990 % variable</penaltyGoToRate>
<q_penaltyGoToRate>18.99</q_penaltyGoToRate>
<lateFee>N/A*</lateFee>
<q_lateFee>999</q_lateFee>
<cashAdvanceFee>N/A*</cashAdvanceFee>
<q_cashAdvanceFee>999</q_cashAdvanceFee>
<balanceTransferFee>No*</balanceTransferFee>
<q_balanceTransferFee>0.00</q_balanceTransferFee>
<foreignCurrencyExchangeFee>2.000%</foreignCurrencyExchangeFee>
<q_foreignCurrencyExchangeFee>2.000</q_foreignCurrencyExchangeFee>
<issuer>Discover</issuer>
</product>
</products>
Y este es el codigo php:
Código PHP:
$file = 'http://ladireccion';
if(!$xml = simplexml_load_file($file))
exit('Failed to open '.$file);
$sitemembers = simplexml_load_file($file);
echo '<ol>';
foreach ($sitemembers->products->product as $member)
{
$ID= $member->id;
$NAME= $member->name;
$DESCRIPTION= $member->description;
$SHORTDESCRIPTION= $member->shortDescription;
$IMAGEPATH= $member->imagepath;
$URL= $member->url;
$INTROAPR= $member->introApr;
$Q_INTROAPR= $member->q_introApr;
$INTROAPRPERIOD= $member->introAprPeriod;
$Q_INTROAPRPERIOD= $member->q_introAprPeriod;
$REGULARAPR= $member->regularApr;
$Q_REGULARAPR= $member->q_regularApr;
$ANNUALFEE= $member->annualFee;
$Q_ANNUALFEE= $member->q_annualFee;
$CREDITNEEDED= $member->creditNeeded;
$Q_CREDITNEEDED= $member->q_creditNeeded;
$BALANCETRANSFERS= $member->balanceTransfers;
$Q_BALANCETRANSFERS= $member->q_balanceTransfers;
$TRANSACTION_FEE_PIN= $member->transaction_fee_pin;
$Q_TRANSACTION_FEE_PIN= $member->q_transaction_fee_pin;
$TRANSACTION_FEE_SIGNATURE= $member->transaction_fee_signature;
$Q_TRANSACTION_FEE_SIGNATURE= $member->q_transaction_fee_signature;
$LOAD_FEE= $member->load_fee;
$Q_LOAD_FEE= $member->q_load_fee;
$ATM_FEE= $member->atm_fee;
$Q_ATM_FEE= $member->q_atm_fee;
$ACTIVATION_FEE= $member->activation_fee;
$Q_ACTIVATION_FEE= $member->q_activation_fee;
$BALANCETRANSFERINTROAPR= $member->balanceTransferIntroApr;
$Q_BALANCETRANSFERINTROAPR= $member->q_balanceTransferIntroApr;
$BALANCETRANSFERINTROAPRPERIOD= $member->balanceTransferIntroAprPeriod;
$Q_BALANCETRANSFERINTROAPRPERIOD= $member->q_balanceTransferIntroAprPeriod;
echo '<li>';
echo $ID.'<br>';
echo $NAME.'<br>';
echo $DESCRIPTION.'<br>';
echo $SHORTDESCRIPTION.'<br>';
echo $IMAGEPATH.'<br>';
echo $URL.'<br>';
echo $INTROAPR.'<br>';
echo $Q_INTROAPR.'<br>';
echo $INTROAPRPERIOD.'<br>';
echo $Q_INTROAPRPERIOD.'<br>';
echo $REGULARAPR.'<br>';
echo $Q_REGULARAPR.'<br>';
echo $ANNUALFEE.'<br>';
echo $Q_ANNUALFEE.'<br>';
echo $CREDITNEEDED.'<br>';
echo $Q_CREDITNEEDED.'<br>';
echo $BALANCETRANSFERS.'<br>';
echo $Q_BALANCETRANSFERS.'<br>';
echo $TRANSACTION_FEE_PIN.'<br>';
echo $Q_TRANSACTION_FEE_PIN.'<br>';
echo $TRANSACTION_FEE_SIGNATURE.'<br>';
echo $Q_TRANSACTION_FEE_SIGNATURE.'<br>';
echo $LOAD_FEE.'<br>';
echo $Q_LOAD_FEE.'<br>';
echo $ATM_FEE.'<br>';
echo $Q_ATM_FEE.'<br>';
echo $ACTIVATION_FEE.'<br>';
echo $Q_ACTIVATION_FEE.'<br>';
echo $BALANCETRANSFERINTROAPR.'<br>';
echo $Q_BALANCETRANSFERINTROAPR.'<br>';
echo $BALANCETRANSFERINTROAPRPERIOD.'<br>';
echo '</li>';
}
echo '</ol>';
?>