Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML 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 October 10th, 2007, 06:24 AM
Authorized User
 
Join Date: Feb 2007
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default append in xml file

Hello everybody !

I want to append in a xml file (if it exists otherwise create, specified xml file). Suppose my file is like-

/***************** append to this file:- test.xml *********/
<AIEE>
<id>1</id>
<name>Raaj</name>
<email>[email protected]</email>
<title>News Posting</title>
<description>News posting provide facilities to post news by public</description>
//......... required append location
<AIEE>
//......... currently append location


************** Appendable contents in file "test.xml" ********

<id>1</id>
<name>pankaj</name>
<email>[email protected]</email>
<title>Cricket match</title>
<description>There will held Cricket match on Oct 25, 2007 between India Vs Pakistan </description>
************************************************** ***



Now suppose i want to append some contents at
//.... Append location(see above). I have to do this by using php4.

I have successed to append my new contents at //.....current append location (see above).

********* php file for append "writexmlfile.xml"*********************
<?
$file_handle = fopen('test.xml','a');
$content=('<?xml version="1.0" ?>
<id>2</id>
<name>pankaj</name>
<email>[email protected]</gmail>
<title>Cricket match</title>
<description>There will held Cricket match on Oct 25, 2007 between India Vs Pakistan </description>');

if(fwrite($file_handle,$content))
    {
    echo"u success to append xml file";
    }
    else
    {
    echo"u failed to append xml file";
    }
    fclose($file_handle);
?>
************************************************** **


Please tell me how can I do so....

thanx for attention !
 
Old October 10th, 2007, 07:37 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Append means just that - Add to the end.

What you actually want to do is add a new child node to the root node of your XML document.

For this you will either have to use some form of XML parser, or you could hack it by loading the entire XML file into a string variable and replacing "</AIEE>" with $content . "</AIEE>" maybe.

/- Sam Judson : Wrox Technical Editor -/
 
Old October 10th, 2007, 09:49 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Never used PHP for XML but the standard DOM method is appendChild which takes a node representing the new data. In your case this would be called on the document element, AIEE. Searching the PHP documentation for those terms should get you some examples.

--

Joe (Microsoft MVP - XML)
 
Old October 11th, 2007, 02:58 AM
Authorized User
 
Join Date: Feb 2007
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Oh !

Thank u very much...I shall try accordingly.......






Similar Threads
Thread Thread Starter Forum Replies Last Post
append a xml node from one file to another pravind XSLT 5 August 22nd, 2009 09:15 AM
append/insert data to xml file andhiez XML 5 April 18th, 2008 11:13 AM
Append Information to a XML file YoungLuke C# 2 July 26th, 2007 02:15 PM
append data to xml andhiez General .NET 0 June 14th, 2005 04:15 AM
VB.NET: Convert String and append to Xml files toytoy Pro VB.NET 2002/2003 0 September 2nd, 2004 10:50 PM





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