View Full Version : Using PHP DOM to create elements not included in DTD

17 Nov 2011, 10:16 AM
I am attempting to use the PHP DOMDocument object to work with SVG namespaces. It works great because it can be validated with the SVG 1.1 DTD. My problem is, I am trying to append HTML5 elements to the SVG document using the referenced namespace. Unfortunately, the HTML namespace is not included in the DTD for SVG 1.1 so PHP throws an error when I try to include the namespace or any elements from it. The elements work fine written out by hand, but I need to do this dynamically... what can I do to make it so I can use DOMDocument? The problem arises from using the $dom->validate() but I like this function. A quick example follows showing what I would like to be output by the DOM:

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg"
version="1.1" baseProfile="full" width="200px" height="200px">

<!-- some SVG stuff -->

<!-- These elements will throw an error in PHP as they are not included in the DTD for SVG 1.1 -->
<html:audio autoplay="true" loop="true">
<html:source src="a.ogg" type="audio/ogg" />
<html:source src="a.mp3" type="audio/mpeg" />