...

View Full Version : parsing xml dom from php error



minkoko
08-08-2012, 12:03 PM
H! everyone
i had one xml script name is call catalog.xml

<?xml version="1.0" encoding="uft-8"?>
<Catalog>
<Product Type="Book" SupplierId="5">
<ProductId>B10</ProductId>
<ProductName>Introduction to XML </ProductName>
<ListPrice>$50.00</ListPrice>
</Product>
<Product Type="CD" SupplierId="5">
<ProductId>C100</ProductId>
<ProductName>JavaScript Ebooks Collection</ProductName>
<ListPrice>$75.00</ListPrice>
</Product>
</Catalog>


and i want to wite this code in the parsexml.php

<?php
$doc=domxml_open_file("http://localhost:70/programming/xml/catalog.xml");
$root=$doc->document.element();
?>
<html>
<head>
<title>Parsing Xml from PHP</title>
</head>
<body>
<h3><?php echo $root->tagname; ?></h3>
<table border="1" width="100%" cellpadding="3" cellspacing="3" style="border-collapse:collapse">
<colgroup>
<col width="5%"/>
</colgroup>
<tr>
<th>No.</th>
<th>Type</th>
<th>ID</th>
<th>Name</th>
<th>Supplier</th>
<th>Price</th>
</tr>
<?php
$nodes=$root->get_elements_by_tagname("Product");
$i=1;
foreach($nodes as $node){
$product_id= " ";
$product_name= " ";
$product_price=" ";
foreach($node->child_nodes() as $child) {
if($child->node_type() == XML_ELEMENT_NODE){
switch($child->node_name()){
case "ProductId" :
$product_id= $child->first_child()->node_value();
break;

case "ProductName":
$product_name=$child->first_child()->node_value();
break;

case "ListPrice":
$product_price =$child->first_child()->node_value();
break;
}
}
}
?>
<tr>
<td align="right"><?php echo $i; ?></td>
<td><?php echo $node->get_attribute("Type"); ?></td>
<td><?php echo $product_id; ?></td>
<td><?php echo $product_name; ?></td>
<td><?php echo $node->get_attribute("SupplierId"); ?></td>
<td><?php echo $product_price; ?></td>
</tr>
<?php
$i++;
}
?>
</table>
</body>
</html>

when i run in localhost i found this error
Fatal error: Call to undefined function domxml_open_file() in C:\xampplite\htdocs\programming\thuzinhein\parsing xml document with php.php on line 2

and i want to upload the xml file in my program xml is insert into my database

anybody ,help me ?please
Thanks,

Fou-Lu
08-08-2012, 05:22 PM
Where have you written the domxml_open_file function (as well as several others)? I don't see it in this script anywhere. This line will also be invalid: $doc->document.element(). The . in PHP is a concat operator, not a dereference operator.

AndrewGSW
08-08-2012, 05:28 PM
Call to undefined function domxml_open_file()

You need to check which version of PHP you're using (locally and server-side) as the default DOM/XML library has changed, and may require installing an extension.

minkoko
08-09-2012, 04:02 AM
Where have you written the domxml_open_file function (as well as several others)?
i test in localhost with xampp

now i fix this problem with php ref
i use like this
<?php
$xmlstr = <<<XML
<?xml version='1.0' standalone='yes'?>
<Catalog>
<Product Type="Book" SupplierId="5">
<ProductId>B10</ProductId>
<ProductName>Introduction to XML </ProductName>
<ListPrice>$50.00</ListPrice>
</Product>
<Product Type="CD" SupplierId="5">
<ProductId>C100</ProductId>
<ProductName>JavaScript Ebooks Collection</ProductName>
<ListPrice>$75.00</ListPrice>
</Product>
</Catalog>
XML;
?>

and

<?php
include 'catalog1.php';
$movies = new SimpleXMLElement($xmlstr);
echo $movies->Product[0]->ListPrice;
?>

it work

but i want to insert database with xml upload

Thanks for reply



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum