मैं कुछ PHP पर काम कर रहा हूं ताकि डीओएम एक्सटेंशन का उपयोग कर डेटाबेस से एक्सएमएल बनाया जा सके।PHP डोम एक्सएमएल - एकाधिक नेमस्पेस विशेषताओं को बनाएँ?
असल में, मैं यह करने के लिए एक नाम स्थान 3 गुण बना सकते हैं और जोड़ने की जरूरत:
<NameSpaceName xmlns="uri:xxx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="uri:xxx">
पूर्ण कोड मैं लिखा है नीचे है:
include_once("includes/connect.php");
$sql = ("SELECT * FROM tableName");
$query = mysql_query($sql) or die("Error: " . mysql_error());
// create a new XML document
$doc = new DomDocument('1.0', 'UTF-8');
// create root node
$root = $doc->createElementNS('uri:xxx', 'PayerRecords');
$root = $doc->appendChild($root);
$root->setAttributeNS('http://www.w3.org/2000/xmlns/' ,'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
$root->setAttributeNS('http://www.w3.org/2000/xmlns/' ,'xsi:schemaLocation', 'uri:xxx');
// process one row at a time
while($row = mysql_fetch_assoc($query)) {
// add node for each row
$occ = $doc->createElement('Content');
$occ = $root->appendChild($occ);
// add a child node for each field
foreach ($row as $fieldname => $fieldvalue) {
$child = $doc->createElement($fieldname);
$child = $occ->appendChild($child);
$value = $doc->createTextNode($fieldvalue);
$value = $child->appendChild($value);
} // foreach
} // while
// get completed xml document
$xml_string = $doc->saveXML();
echo $xml_string;
लेकिन जब मैं ऊपर मैं निष्पादित यह त्रुटि प्राप्त करें:
Fatal error: Uncaught exception 'DOMException' with message 'Namespace Error' in xml.php:21 Stack trace: #0 xml.php(21): DOMElement->setAttributeNS(' http://www.w3.o ...', 'xsi:schemaLocat...', 'uri:xxx...') #1 {main} thrown in xml.php on line 21
लाइन 21 दूसरी 'setAttributeNS' पंक्ति है।
क्या कोई देख सकता है कि मैं कहां गलत हो रहा हूं?