function outputXML($dates) { $doc = new DomDocument('1.0'); $root = $doc->createElement('root'); $root = $doc->appendChild($root); for ($i = 0; $i < count($dates); $i++) { $date_node = $doc->createElement('date'); $date_node = $root->appendChild($date_node); appendAttribute($doc, $date_node, "full", $dates[$i]); appendAttribute($doc, $date_node, "date", _parseDate($dates[$i])); } $xml_string = $doc->saveXML(); echo "{$xml_string}"; }
function appendNewsNodeItems($newsNode, $newsitem) { global $doc, $root; appendAttribute($doc, $newsNode, 'url', $newsitem['url']); appendAttribute($doc, $newsNode, 'id', $newsitem['id']); $sectionNode = appendElement($doc, $newsNode, 'section'); appendTextNode($doc, $sectionNode, $newsitem['section']); $headlineNode = appendElement($doc, $newsNode, 'headline'); appendTextNode($doc, $headlineNode, urldecode($newsitem['headline'])); $summaryNode = appendElement($doc, $newsNode, 'summary'); appendTextNode($doc, $summaryNode, urldecode($newsitem['summary'])); $byNode = appendElement($doc, $newsNode, 'byline'); appendTextNode($doc, $byNode, $newsitem['byline']); $updatedNode = appendElement($doc, $newsNode, 'updatedTime'); appendTextNode($doc, $updatedNode, $newsitem['updatedTime']); $createdNode = appendElement($doc, $newsNode, 'createdTime'); appendTextNode($doc, $createdNode, $newsitem['createdTime']); $pubNode = appendElement($doc, $newsNode, 'pubDate'); appendTextNode($doc, $pubNode, $newsitem['pubDate']); }