Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 3rd, 2007, 06:04 AM
Authorized User
 
Join Date: Feb 2007
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default write into xml file in php

Hi..
I m rapraj...! I want to write into xml file.
Suppose myxml file is:


//********************* newspost.xml ********************

<?
$xmlstr = "<?xml version='1.0' standalone='yes'?>
<!DOCTYPE chapter SYSTEM '/share/sgml/Norman_Walsh/db3xml10/db3xml10.dtd'
[ <!ENTITY sp \"spanish\">]>

  <IEEE ID='findme' language='&sp;'>
    <tbody>
     <id>1</id>
     <name>raj</name>
     <email>[email protected]</email>
     <title>India Vs Pakistan Cricket match</title>
     <description>India Vs Pakistan cricket match will in Kanpur on Nov11 2007</description>
    </tbody>
                          //I want to write next contents here
  </IEEE>";
?>
//************************************************** ****



//Code for writing my next content before closing </IEEE> tag
//************************************************** ******

include("passwordfile/newspost.xml");

        if (!$dom = domxml_open_mem($xmlstr))
                {
                echo "Error while parsing the document\n";
                exit;
                }


        $elements = $dom->get_elements_by_tagname("tbody");
        //print_r($elements);
        $element = $elements[0];

        $parent = $element->parent_node();
        $newnode = $parent->append_child($element);
        $children = $newnode->children();
        $children = $newnode->newcontent();
        $attr = $children[1]->set_attribute("align", "left");

        $xmlfile = $dom->dump_mem();
        echo htmlentities($xmlfile);
?>

The above code is displaying very well I made the changes as below, to get the new contents field up by any user through GUI :

//************************************************** ***********

include("passwordfile/newspost.xml");

function newcontent()
        {
        $newcont="<tbody>\r\n<id>".$id."</id>\r\n<name>".$name."</name>\r\n<email>".$email."</email>\r\n<newstitle>".$newstitl
e."</newstitle>\r\n<description>".$description."</description>\r\n</tbody>";
        //$args=$newcont;
        return $newcont;
        }


        if (!$dom = domxml_open_mem($xmlstr))
                {
                echo "Error while parsing the document\n";
                exit;
                }

        $news="<tbody>\r\n<id>".$id."</id>\r\n<name>".$name."</name>\r\n<email>".$email."</email>\r\n<newstitle>".$newstitle."
</newstitle>\r\n<description>".$description."</description>\r\n</tbody>";

        $elements = $dom->get_elements_by_tagname("tbody");
        //print_r($elements);
        $element = $elements[0];

        $parent = $element->parent_node();
        //$newnode = $parent->append_child($element);
        $newnode = $parent->append_child($news);
        //$children = $newnode->children();
        $children = $newnode->newcontent();
        $attr = $children[1]->set_attribute("align", "left");

        $xmlfile = $dom->dump_mem();
        echo htmlentities($xmlfile);
?>

//********** THE ERROR ARE

Warning: append_child() expects parameter 1 to be object, string given in /var/www/html/ieee/raajappend.php on line 44

Fatal error: Call to a member function on a non-object in /var/www/html/ieee/raajappend.php on line 46

So please suggest me for the exact output
Thanx in advance..






Similar Threads
Thread Thread Starter Forum Replies Last Post
write HTML into TEXTAREA using PHP anshul PHP How-To 6 March 27th, 2009 12:15 PM
How Silverlight write data to XML file? tomalani Other Programming Languages 0 May 15th, 2008 07:31 AM
Help with PHP file reading XML file for output rydog65 Beginning PHP 0 March 26th, 2008 05:13 PM
Read, write, delete and display xml file in php rapraj XML 0 December 27th, 2007 02:18 AM
xml invalid top level from ASP write XML(solution) g000we XML 0 August 9th, 2006 03:56 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.