I'm trying to create an XML document that looks something like this...
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE stylesheet [
<!ENTITY nbsp " ">
<!ENTITY copy "©">
<!ENTITY reg "®">
<!ENTITY trade "™">
<!ENTITY mdash "—">
<!ENTITY ldquo "“">
<!ENTITY rdquo "”">
<!ENTITY pound "£">
<!ENTITY yen "¥">
<!ENTITY euro "€">
]>
<NewsPost>
<Post>
<PermaLink>http://news.bradfordastronomy.co.uk/?p=92</PermaLink>
<Title>Change of Venue for Monday Meetings until March 2015</Title>
<Content>Due to building work at Eccleshill library, the Monday meetings will be held at Upper Bolton Conservative Club, Idle Road, Bradford, BD2 4JN.
<span style="color: #ffff00"><strong>Update </strong></span>
The building work is taking longer than expected; however, we hope to be back at the Library by the end of March 2015.</Content></Post></NewsPost>
I'm tring to do this using PHP. The current code that I have so far is this...
$imp = new DOMImplementation;
$dtd = $imp->createDocumentType('stylesheet', '', '');
$domDoc = new DOMDocument('1.0', 'utf-8');
$domDoc->preserveWhiteSpace = false;
require_once(newsFolder.'/wp-blog-header.php');
//global $post;
$args = array( 'posts_per_page' => 1 );
$myposts = get_posts( $args );
$rootElement = $domDoc->createElement('NewsPost');
$domDoc->appendChild($rootElement);
foreach( $myposts as $post ) : setup_postdata($post);
$postNode = $domDoc->createElement("Post");
$rootElement->appendChild($postNode);
$permaLinkNode = $domDoc->createElement("PermaLink",get_permalink());
$postNode->appendChild($permaLinkNode);
$titleNode = $domDoc->createElement("Title",get_the_title());
$postNode->appendChild($titleNode);
//$contentNode = $domDoc->createElement("Excerpt",get_the_excerpt());
//$postNode->appendChild($contentNode);
$contentNode = $domDoc->createElement("Content",get_the_content());
$postNode->appendChild($contentNode);
endforeach;
$domDoc->save(cacheFolder.'LatestWordPressEntry.xml');
unset($domDoc);
You'll notice that there is no code to add the tags to the !DOCTYPE
I'm looking all over the net and can't see the best practice method of doing this. I really do not want to resort to saving the XML to a string, then doing a string replace (which is always a huge cludge)
Any help on this would be greatly appreciated.
Bascially, I'm looking to turn the
<!DOCTYPE stylesheet>
tag into
<!DOCTYPE stylesheet [
<!ENTITY nbsp " ">
<!ENTITY copy "©">
<!ENTITY reg "®">
<!ENTITY trade "™">
<!ENTITY mdash "—">
<!ENTITY ldquo "“">
<!ENTITY rdquo "”">
<!ENTITY pound "£">
<!ENTITY yen "¥">
<!ENTITY euro "€">
]>