Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Aug 2010
    Location
    myeik
    Posts
    81
    Thanks
    6
    Thanked 5 Times in 5 Posts

    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,

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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.

  • #3
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    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

  • #4
    New Coder
    Join Date
    Aug 2010
    Location
    myeik
    Posts
    81
    Thanks
    6
    Thanked 5 Times in 5 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •