Click to See Complete Forum and Search --> : XML Parsing Error: no element found (help? *puppy eyes*)


kyla
09-26-2005, 03:55 PM
I just started a course on xml and I am completely lost in a number of places. Just when I thought I figured everything out, I get this error:

XML Parsing Error: no element found
Location: file:///C:/Documents%20and%20Settings/Me/Desktop/xml%20assign/doc.xml
Line Number 79, Column 11:</invoice>
----------^

and here is my xml document:

<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/css" href="invoice.css"?>

<document xmlns:xlink = "http://www.w3.org/1999/XLink">
<!-- Invoice written by Kyla Cohen -->

<invoice>
<invoice-header>
<invoice-date>Sunday, September 19, 2005</invoice-date>
<payment-date>Sunday, September 26, 2005</payment-date>
<contract-number>4903-02</contract-number>
<currency>Canadian Dollars (CND)</currency>
<supplier-data>
<supplier-order-number>93900-022</supplier-order-number>
<supplier-name>Toyota Cars Ltd.</supplier-name>
<supplier-address>4903 No. 6 Road</supplier-address>
<supplier-city>Richmond</supplier-city>
<supplier-province>British Columbia</supplier-province>
<supplier-postal-code>v9j4g8</supplier-postal-code>
<supplier-country>Canada</supplier-country>
<supplier-telephone-number>604-276-0494</supplier-telephone-number>
</supplier-data>
<buyer-data>
<buyer-order-number>3044-9449-320</buyer-order-number>
<buyer-name>Russell Pope</buyer-name>
<buyer-address>5456 Grove Avenue</buyer-address>
<buyer-city>Delta</buyer-city>
<buyer-province>British Columbia</buyer-province>
<buyer-postal-code>v4k2a7</buyer-postal-code>
<buyer-country>Canada</buyer-country>
<buyer-telephone-number>604-946-9487</buyer-telephone-number>
</buyer-data>
</invoice-header>
<invoice-details>
<supplier-part-id>2005-Corolla</supplier-part-id>
<description>
<car-name>2005 Toyota Corolla</car-name>
<car-color>Red</car-color>
<car-door>4 Door</car-door>
<car-addons>Air Condition, CD Player, and Leather Interior</car-addons>
</description>
<quantity>1</quantity>
<unit-price>$25,000.00</unit-price>
<entended-amount>$21,000.00</entended-amount>
</invoice-details>
<invoice-details>
<supplier-part-id>2005-Celica</supplier-part-id>
<description>
<car-name>2005 Toyota Celica</car-name>
<car-color>Navy Blue</car-color>
<car-door>2 Door</car-door>
<car-addons>Air Condition, and CD Player</car-addons>
</description>
<quantity>2</quantity>
<unit-price>$23,000.00</unit-price>
<entended-amount>$46,000.00</entended-amount>
</invoice-details>
<invoice-details>
<supplier-part-id>2005-Scion</supplier-part-id>
<description>
<car-name>2005 Toyota Scion</car-name>
<car-color>Silver</car-color>
<car-door>4 Door</car-door>
<car-addons>Air Condition, CD Player, and Automatic Windows</car-addons>
</description>
<quantity>1</quantity>
<unit-price>$15,000.00</unit-price>
<entended-amount>$15,000.00</entended-amount>
</invoice-details>
<invoice-summary>
<subtotal>$82,000.00</subtotal>
<tax>
<tax-percent>15%</tax-percent>
<tax-amount>$12,300.00</tax-amount>
<taxable-amount>$82,000.00</taxable-amount>
</tax>
<total>$94,300.00</total>
</invoice-summary>
</invoice>


I can't figure out what's wrong or what I'm missing, any ideas? Thanks in advance!

Charles
09-26-2005, 04:09 PM
I'm a cat person myself; I prefer the taste. However, you seem to have forgotten to close your root element "document".

kyla
09-26-2005, 05:07 PM
Wow, how completely embarressed I am for neglecting to see that simple error. Thank you very much for pointing that out Charles!

jonnyfive
11-05-2005, 05:45 AM
i see where she made a simple mistake and that caused her error i presume. I'm having difficulties getting a rate request back from UPS using a script that works on one server but does not work with the same code on a different server. I keep getting the error no element found at line 1 which is returned from

if (!xml_parse($xml_parser, $data, TRUE)) {
die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)));
}

does that error occur when the response is not received, or is formed wrong?

Stephen Philbin
11-06-2005, 08:01 AM
Is that PHP 4 that you're using there? jonnyfive?

jonnyfive
11-06-2005, 04:09 PM
its php 4.4.0 .. what i'm trying to do is get shipping rates from UPS. funny thing is that on one server i already have the code written in php using cUrl to get the rates. that php version is 4.3.11 and it works . on the server with php 4.4.0 installed i get the error message no element found at line 1. when i echo the data that comes back from UPS, it shows "0" . I'm just wondering if i'm getting any data back or not. I just don't know the version differences enough to be able to pinpoint why the request from the server with 4.4.0 is answered with a 0 whereas the other server works fine.. Any ideas?

Thanks,

Jonnyfive

jonnyfive
11-06-2005, 04:12 PM
First i do some jiggery work to figure out the weight and assign the variables their respective values

if ($totalWeight > 0) {
$xml = "
<?xml version=\"1.0\" ?>
<AccessRequest xml:lang=\"en-US\">
<AccessLicenseNumber>$upskey</AccessLicenseNumber>
<UserId>$upsusername</UserId>
<Password>$upspassword</Password>
</AccessRequest>
<?xml version=\"1.0\" ?>
<RatingServiceSelectionRequest xml:lang=\"en-US\">
<Request>
<TransactionReference>
<CustomerContext>Bare Bones Rate Request</CustomerContext>
<XpciVersion>1.0</XpciVersion>
</TransactionReference>
<RequestAction>Rate</RequestAction>
<RequestOption>Rate</RequestOption>
</Request>
<PickupType>
<Code>01</Code>
</PickupType>
<Shipment>
<Shipper>
<Address>
<PostalCode>$shippingFromPostalCode</PostalCode>
<CountryCode>US</CountryCode>
</Address>
</Shipper>
<ShipTo>
<Address>
<PostalCode>$shippingToPostalCode</PostalCode>
<CountryCode>$shippingToCountryCode</CountryCode>
</Address>
</ShipTo>
<ShipFrom>
<Address>
<PostalCode>$shippingFromPostalCode</PostalCode>
<CountryCode>$shippingFromCountryCode</CountryCode>
</Address>
</ShipFrom>
<Service>
<Code>$serviceType</Code>
</Service>
<Package>
<PackagingType>
<Code>02</Code>
</PackagingType>
<Dimensions>
<UnitOfMeasurement>
<Code>IN</Code>
</UnitOfMeasurement>
<Length>0</Length>
<Width>0</Width>
<Height>0</Height>
</Dimensions>
<PackageWeight>
<UnitOfMeasurement>
<Code>$shippingWeightUnit</Code>
</UnitOfMeasurement>
<Weight>$totalWeight</Weight>
</PackageWeight>
</Package>
</Shipment>
</RatingServiceSelectionRequest>
" ;
// send into the ups
$post = "POST /ups.app/xml/Rate HTTP/1.0
Content-length: ".strlen($xml)."
Content-type: text/xml
host: www.ups.com
connection: close

$xml";

/* Initialize the parser. */
$inTotalCharges=0;
$inMonetaryValue=0;
global $shippingCharges;
$shippingCharges=0;

$csess = curl_init();
curl_setopt($csess, CURLOPT_URL, "https://www.ups.com/ups.app/xml/Rate");
curl_setopt($csess, CURLOPT_HEADER, 0);
curl_setopt($csess, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($csess, CURLOPT_CUSTOMREQUEST, $post);
$data = curl_exec($csess);
echo "<!--$data-->";
curl_close($csess);
$xml_parser = xml_parser_create('ISO-8859-1');
xml_set_character_data_handler($xml_parser, "characterData");
xml_set_element_handler($xml_parser, 'StartHandler', 'EndHandler');

if (!xml_parse($xml_parser, $data, TRUE)) {
die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)));
}
xml_parser_free($xml_parser);
} else {
$shippingCharges = 0;
}
return $shippingCharges;
}

function characterData($parser, $data) {
global $inTotalCharges,$inMonetaryValue;
global $shippingCharges;
if (($inTotalCharges==1)&&($inMonetaryValue==1)) {
if ($shippingCharges ==0) {
$shippingCharges = $data;
}
}
}

function startHandler($parser, $name, $attrs) {
global $inTotalCharges,$inMonetaryValue;
if ($name == "TOTALCHARGES") { $inTotalCharges = 1; }
if ($name == "MONETARYVALUE"){ $inMonetaryValue = 1; }
}

function endHandler($parser, $name) {
global $inTotalCharges,$inMonetaryValue;
if ($name == "TOTALCHARGES") { $inTotalCharges = 0; }
if ($name == "MONETARYVALUE"){ $inMonetaryValue = 0; }
}

Stephen Philbin
11-06-2005, 10:46 PM
I think your problem is that XML in PHP 4 is a bit cack. There are a few ways to handle XML in PHP 4, they are all different, and as far as I know, none of them properly comply with any standards. To make matters worse, the behaviour of each method of handling XML in PHP 4 can vary significantly (or just not work at all) depending on which XML libraries your PHP module links to and which version of the library it uses is too.

I think the first thing you should check is which versions of libxml each server has installed. Try to get them matched up.