XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
1200+ fellow developers rate and compare features of the top IDEs, like Visual Studio, Eclipse, RAD, Delphi and others, across 13 categories. Enjoy this FREE Download of the IDE User Satisfaction Study by Evans Data Corporation. Download Now!
  #1  
Old May 2nd, 2002, 02:13 PM
UrbanDeveloper UrbanDeveloper is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Posts: 209 UrbanDeveloper User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Exclamation xml tree needs tweaking....

Hey there,

I am trying to develop a php file to log certain data into an xml file. The coding seems to work however the second time around the data is not saved on the xml file.

Heres the code :

$xml_string =

"<errorlog>
<report>
<host>$host</host>
<ipaddress>$ip</ipaddress>
<errmsg>$subject</errmsg>
<date>$dt</date>
</report>
</errorlog>
";

and heres the error msg :

Only one top level element is allowed in an XML document. Error processing resource 'file://wwwroot/errorlog.xml'. Line 9, Position 2


<errorlog>
-^

The error i guess is because the second time around the script attempts to create the top level <errorlog> again. Is there a way to check for its presence or to avoid it from doing that ?!

Appreciate your help !

Urban Dev

Reply With Quote
  #2  
Old June 3rd, 2002, 05:00 PM
alexgreg's Avatar
alexgreg alexgreg is offline
Full Access
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jun 2000
Location: London, UK
Posts: 2,019 alexgreg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 sec
Reputation Power: 11
Try this (assuming that your file contains <errorlog> and </errorlog> tags already):


PHP Code:
<?

$report 
"
<report> 
<host>$host</host> 
<ipaddress>$ip</ipaddress> 
<errmsg>$subject</errmsg> 
<date>$dt</date> 
</report>"
;

$fp fopen("error_log.xml""r");
$data fread($fpfilesize("error_log.xml"));

$data str_replace ("</errorlog>",$report."</errorlog>",$data);

fclose($fp);

$fp2 fopen("error_log.xml""w");

fputs($fp2$data);
fclose($fp2);

?>
__________________
Alex
(http://www.alex-greg.com)

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > xml tree needs tweaking....


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway