PDA

View Full Version : ساخت فایل xml در php



monaizadi
شنبه 09 شهریور 1387, 10:05 صبح
سلام
دستوری توی php وجود داره که به database وصل بشه و فایل xml اون رو تولید کنه؟


با این کد تونستم تولید کنم، اما می خوام بدونم دستوری وجود نداره که مستقیما این کار رو انجام بده؟


$outer_table = 'createxml';
$query = "SELECT * FROM $outer_table ";
$resouter = mysql_query($query, $dbconnect);

$doc = new DomDocument('1.0');

// add root node
$root = $doc->createElement('root');
$root = $doc->appendChild($root);
//add node for parent/outer table
$outer = $doc->createElement($outer_table);
$outer = $root->appendChild($outer);
// take only one row from parent/outer table
// process all rows of the inner/many/child table
while ($row = mysql_fetch_assoc($resouter))
{
// add node for each record
$inner = $doc->createElement($outer_table);
$inner = $outer->appendChild($inner);
// add a child node for each field
foreach ($row as $fieldname => $fieldvalue) {
$child = $doc->createElement($fieldname);
$child = $inner->appendChild($child);
$value = $doc->createTextNode($fieldvalue);
$value = $child->appendChild($value);
} // foreach
} // while
// get completed xml document
$test1 = $doc->saveXML(); // put string in test1
$doc->save('xmlphp.xml');
//$->saveXML('xmlphp.xml');
//echo $xml_string;

tabib_m
یک شنبه 10 شهریور 1387, 18:17 عصر
سلام
بهتر بود در انجمن PHP مطرح میکردید...

نه، دستور مستقیمی وجود نداره... باید خودتون کد بنویسید...

موفق باشید.