Im trying to create WXR file from scratch (WordPress eXtended Rss).
My code is based on XML/WXR file generated by wordpress and starts like this:
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0"
xmlns:excerpt="http://wordpress.org/export/1.2/excerpt/"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:wp="http://wordpress.org/export/1.2/"
>
I started like this:
$newxml = new SimpleXMLElement("<rss></rss>");
$newxml->addAttribute('version', '2.0');
$newxml->addAttribute('xmlns:excerpt', 'http://wordpress.org/export/1.2/excerpt/');
$newxml->addAttribute('xmlns:content', 'http://purl.org/rss/1.0/modules/content/');
$newxml->addAttribute('xmlns:wfw', 'http://wellformedweb.org/CommentAPI/');
$newxml->addAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
$newxml->addAttribute('xmlns:wp', 'http://wordpress.org/export/1.2/');
After this im printing XML like this:
echo htmlspecialchars($newxml->asXML());
Im getting XML like this:
<?xml version="1.0"?>
<rss version="2.0"
excerpt="http://wordpress.org/export/1.2/excerpt/"
content="http://purl.org/rss/1.0/modules/content/"
wfw="http://wellformedweb.org/CommentAPI/"
dc="http://purl.org/dc/elements/1.1/"
wp="http://wordpress.org/export/1.2/">
<channel/>
</rss>
(i added line breaks for better readability).
How i can force full attributes, like “xmlns:excerpt” instead of just “excerpt”?
The part before the colon is called “namespace” and needs to be specified separately. For
addAttribute
it is the third parameter: