Skip to content

Instantly share code, notes, and snippets.

@blar
Last active August 29, 2015 14:10
Show Gist options
  • Save blar/c351ef96a09b8f20797f to your computer and use it in GitHub Desktop.
Save blar/c351ef96a09b8f20797f to your computer and use it in GitHub Desktop.
Entwurf zu DOM
<?php
$document = new DomDocument();
$atom = $document->getNamespace('http://www.w3.org/2005/Atom');
$xhtml = $document->getNamespace('http://www.w3.org/1999/xhtml', 'xhtml');
$feed = $atom->createElement('feed');
$document->appendChild($feed);
$entry = $atom->createElement('entry');
$title = $atom->createElement('title')->appendChild('Hello World');
$entry->appendChild($title);
$content = $atom->createElement('content')->setAttribute('type', 'xhtml');
$content->appendChild($xhtml->createElement('p')->appendChild('Hello World'));
$entry->appendChild($content);
$feed->appendChild($entry);
$document->normalizeNamespaces([$atom, $xhtml]);
echo $document;
<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:xhtml="http://www.w3.org/1999/xhtml">
<entry>
<title>Hello World</title>
<content type="xhtml">
<xhtml:p>Hello World</xhtml:p>
</content>
</entry>
</feed>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment