|
|
|
|
![]() ![]() |
Mar 27 2007, 12:05 PM
Post
#1
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 357 Joined: 8-April 06 Member No.: 21,487 |
hi all ,
i have one big problem i need to know , how i can read xml file and then save strings in xml in database for example its my xml CODE <?xml version="1.0"?> <numbers> <arash>1</arash> <kiarash>2</kiarash> </numbers> i want my soruce read this xml file and then save <arash> string into arash field in mysql database for example in this source arash string is " 1" and kiarash string is "2" my fields in mysql are standard and we have 2 field with names "arash" and "kiarash" please help me , if you know some tut about this subject thanks |
|
|
|
Mar 29 2007, 12:50 PM
Post
#2
|
|
|
Newbie [Level 1] ![]() Group: Members Posts: 14 Joined: 29-March 07 Member No.: 40,791 |
I suppose you could use an fopen("xml.xml" "r"); statement and then use some explodes to get the numbers...
CODE <?php if(!$handle = fopen("file.xml", "w")) { echo "Could not open the file."; exit; } if (!is_readable("file.xml")) { echo "The file is not readable!"; exit; } $contents = fread($handle, filesize($filename)); $getarash = explode($contents, "<arash>"); $getarash2 = explode($arash[1], "</arash"); $arash = $getarash2[0]; fclose($handle); ?> But, it is easier to just update the xml file from the database through PHP automatically with a cron job or something... CODE <?php
if(!$handle = fopen("somefile.xml", "w")) { echo "Can't open the file"; } if (!is_writable("somefile.xml")) { echo "The file is not writable!"; } $xml .= <<<EOF <?xml version="1.0"?> <numbers> EOF; $conn = mysql_connect('localhost, 'dbuser', 'dbpass'); mysql_select_db('dbname'); $query = @mysql_query("SELECT number FROM `arash`"); $arash = @mysql_fetch_assoc($query); $xml .= <<<EOF <arash>{$arash['number']}</arash> EOF; //Etc for kiarash $xml .= <<<EOF </numbers> EOF; if (fputs($handle, $xml) === FALSE) { echo "Cannot write to xml file"; exit; } fclose($handle); mysql_close($conn); ?> This post has been edited by jebriggsy: Mar 29 2007, 12:54 PM |
|
|
|
Mar 29 2007, 08:58 PM
Post
#3
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 413 Joined: 4-October 06 From: Psychedelic Realms Member No.: 31,079 |
For reading XML with php you need to use something like this (this example even ads XSL stylesheet to XML)
CODE $xmldoc = new DOMDocument(); $xmldoc->loadXML('yourxmlfile.xml'); $xsldoc = new DOMDocument(); $xsldoc->loadXML('yourstylesheet.xsl'); $xslt = new XSLTProcessor(); $xslt->importStylesheet($xsldoc); echo $xslt->transformToXML($xmldoc); Just a thing i was wondering, does trap17 have support for XSLTProcessor?! |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 11th October 2008 - 08:41 PM |