Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-08-2012, 11:03 AM   PM User | #1
minkoko
New Coder

 
Join Date: Aug 2010
Location: myeik
Posts: 72
Thanks: 4
Thanked 5 Times in 5 Posts
minkoko can only hope to improve
parsing xml dom from php error

H! everyone
i had one xml script name is call catalog.xml
Code:
<?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
Code:
<?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,
minkoko is offline   Reply With Quote
Old 08-08-2012, 04:22 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 08-08-2012, 04:28 PM   PM User | #3
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Quote:
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.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Old 08-09-2012, 03:02 AM   PM User | #4
minkoko
New Coder

 
Join Date: Aug 2010
Location: myeik
Posts: 72
Thanks: 4
Thanked 5 Times in 5 Posts
minkoko can only hope to improve
Quote:
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
Code:
<?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
Code:
<?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
minkoko is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:48 AM.


Advertisement
Log in to turn off these ads.