Jump to content

php xml


macKeet

Recommended Posts

Newbie...Can anyone help me solve this problem....

Loaded this xml and php file onto my server and got the htm response below

.....................................................

 

<?xml version="1.0"?>

 

<invoice>

 

  <customer>

      <name>Joe Wannabe</name>

      <address>

        <line>23, Great Bridge Road</line>

        <line>Bombay, MH</line>

        <line>India</line>

      </address>

  </customer>

 

  <date>2001-09-15</date>

 

  <reference>75-848478-98</reference>

 

  <items>

      <item cid="AS633225">

        <desc>Oversize tennis racquet</desc>

        <price>235.00</price>

        <quantity>1</quantity>

        <subtotal>235.00</subtotal>

      </item>

 

      <item cid="GT645">

        <desc>Championship tennis balls (can)</desc>

        <price>9.99</price>

        <quantity>4</quantity>

        <subtotal>39.96</subtotal>

      </item>

 

      <item cid="U73472">

        <desc>Designer gym bag</desc>

        <price>139.99</price>

        <quantity>1</quantity>

        <subtotal>139.99</subtotal>

      </item>

 

      <item cid="AD848383">

        <desc>Custom-fitted sneakers</desc>

        <price>349.99</price>

        <quantity>1</quantity>

        <subtotal>349.99</subtotal>

      </item>

  </items>

 

  <delivery>Next-day air</delivery>

 

</invoice>

.....................................

<html>

<head>

<basefont face="Arial">

</head>

<body bgcolor="white">

 

<font size="+3">Sammy's Sports Store</font>

<br>

<font size="-2">14, Ocean View, CA 12345, USA  http://www.sammysportstore.com/</font>

<p>

<hr>

<center>INVOICE</center>

<hr>

<?php

 

// arrays to associate XML elements with HTML output

$startTagsArray = array(

'CUSTOMER' => '<p> <b>Customer: </b>',

'ADDRESS' => '<p> <b>Billing address: </b>',

'DATE' => '<p> <b>Invoice date: </b>',

'REFERENCE' => '<p> <b>Invoice number: </b>',

'ITEMS' => '<p> <b>Details: </b> <table width="100%" border="1" cellspacing="0"  cellpadding="3"><tr><td><b>Item description</b></td><td><b>Price</b></td><td><b>  Quantity</b></td><td><b>Sub-total</b></td></tr>',

'ITEM' => '<tr>',

'DESC' => '<td>',

'PRICE' => '<td>',

'QUANTITY' => '<td>',

'SUBTOTAL' => '<td>',

'DELIVERY' => '<p> <b>Shipping option:</b> ',

'TERMS' => '<p> <b>Terms and conditions: </b> <ul>',

'TERM' => '<li>'

);

 

$endTagsArray = array(

'LINE' => ',',

'ITEMS' => '</table>',

'ITEM' => '</tr>',

'DESC' => '</td>',

'PRICE' => '</td>',

'QUANTITY' => '</td>',

'SUBTOTAL' => '</td>',

'TERMS' => '</ul>',

'TERM' => '</li>'

);

 

// array to hold sub-totals

$subTotals = array();

.....................................

//get this response?

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<!-- saved from url=(0046)http://www.mywebsite.com/invoice_xml/invoice.php -->

<HTML><HEAD>

<META http-equiv=Content-Type

content="text/html; charset=windows-1252"><BASEFONT face=Arial>

<META content="MSHTML 6.00.6000.16414" name=GENERATOR></HEAD>

<BODY bgColor=white><FONT size=+3>Sammy's Sports Store</FONT> <BR><FONT

size=-2>14, Ocean View, CA 12345, USA http://www.sammysportstore.com/</FONT>

<P>

<HR>

 

<CENTER>INVOICE</CENTER>

<HR>

<BR><B>Warning</B>: xmldocfile(): I/O in

<B>e:\inetpub\esvc001204\invoice_xml\invoice.php</B> on line

<B>52</B><BR><BR><B>Warning</B>: xmldocfile(): warning : in

<B>e:\inetpub\esvc001204\invoice_xml\invoice.php</B> on line

<B>52</B><BR><BR><B>Warning</B>: xmldocfile(): failed to load external entity

"/home/sammy/invoices/invoice.xml" in

<B>e:\inetpub\esvc001204\invoice_xml\invoice.php</B> on line

<B>52</B><BR><BR><B>Fatal error</B>: Call to a member function on a non-object

in <B>e:\inetpub\esvc001204\invoice_xml\invoice.php</B> on line <B>55</B><BR>PHP

Warning: xmldocfile(): I/O in e:\inetpub\esvc001204\invoice_xml\invoice.php on

line 52 PHP Warning: xmldocfile(): warning : in

e:\inetpub\esvc001204\invoice_xml\invoice.php on line 52 PHP Warning:

xmldocfile(): failed to load external entity "/home/sammy/invoices/invoice.xml"

.............................................

 

Regards

 

Link to comment
https://forums.phpfreaks.com/topic/39972-php-xml/
Share on other sites

If you have PHP5 you could

 

<?php
  $inv = simplexml_load_file('invoice1.xml');
  
  echo $inv->customer->name, '<br>';
  
  foreach ($inv->customer->address->line as $l) {
    echo $l, '<br>';
  }
  
  echo "<table border='1' cellpadding='3' cellspacing='0' width='600'>";
  echo "<tr><th> Date </th><th> Reference </th><th> Delivery </th></tr>";
  echo "<tr><td>" . date ('jS M Y', strtotime($inv->date)) . "</td><td> $inv->reference </td><td> $inv->delivery </td></tr>";
  echo '</table>';
   
  $tot = 0;
  echo "<table border='1' cellpadding='3' cellspacing='0' width='600'>";
  echo "<tr><th> Item<br>code </th><th> Description </th><th> Quantity </th><th> Unit<br>price </th><th> Price </th></tr>";
  foreach ($inv->items->item as $itm) {
    echo "<tr><td> {$itm['cid']} </td><td> $itm->desc </td><td align='center'> $itm->quantity </td><td align='right'> $itm->price </td><td align='right'> $itm->subtotal </td></tr>";
    $tot += floatval($itm->subtotal) ;
  }
  echo "<tr><td colspan='4'> Invoice total </td><td align='right'>" . number_format($tot, 2) . "</td></tr>"; 
  echo '</table>' 
?>

Link to comment
https://forums.phpfreaks.com/topic/39972-php-xml/#findComment-193316
Share on other sites

Thank you for the promp answer but still getting this reply...

 

Fatal error: Call to undefined function: simplexml_load_file() in e:\inetpub\esvc001204\invoice_xml\invoice.php on line 2

PHP Fatal error: Call to undefined function: simplexml_load_file() in e:\inetpub\esvc001204\invoice_xml\invoice.php on line 2

 

Regards

Link to comment
https://forums.phpfreaks.com/topic/39972-php-xml/#findComment-193362
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.