blob: 54d8faa09c1345199fd62587306deee292a8373e [file] [log] [blame]
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<svg onload="init()" width="100%" height="100%" xmlns="http://www.w3.org/2000/svg">
<foreignObject width="100%" height="100%">
<html xmlns="http://www.w3.org/1999/xhtml">
<div id="log">
This tests assures dynamic SVGDocument creation via DOMParser interface works.
</div>
</html>
</foreignObject>
<script>
<![CDATA[
function log(message) {
var logDiv = document.getElementById('log');
var newDiv = document.createElementNS("http://www.w3.org/1999/xhtml",'div');
newDiv.appendChild(document.createTextNode(message));
logDiv.appendChild(newDiv);
}
function init() {
// Prepare SVG Content as string.
var documentString = "<svg xmlns='http://www.w3.org/2000/svg' width='400' height='400'>" +
"<g transform='translate(-50, -50)'>" +
"<path id='path' onclick='mouseHandler(evt)' fill='#FF0000' stroke='#00C000' " +
"d='M 250 130 C 185 130 150 80 150 80 S 115 25 50 25 m 0 105 c 65 0 100 -50 100 -50 s 35 -55 100 -55'/>" +
"</g></svg>";
// Use DOMParser interface to create a SVGDocument datastructure from SVG content string
var parser = new DOMParser();
var svgDocument = parser.parseFromString(documentString, "image/svg+xml");
log("DOMParser.parseFromString returned: " + svgDocument + " should be: [object SVGDocument]");
// Try some operations on the new document
log("SVGDocument's rootElement: " + svgDocument.rootElement + " should be: [object SVGSVGElement]");
log("SVGDocument's rootElement width: " + svgDocument.rootElement.width.baseVal.value + " should be: 400");
log("SVGDocument's rootElement height: " + svgDocument.rootElement.height.baseVal.value + " should be: 400");
log("SVGDocument's rootElement first child: " + svgDocument.rootElement.firstChild + " should be: [object SVGGElement]");
// Use XMLSerializer interface to return a textual presentation of the newly created document
var serializer = new XMLSerializer();
var svgDocumentString = serializer.serializeToString(svgDocument);
log("XMLSerializer.serializeToString returned: " + svgDocumentString);
// Import all children of the new document's root element in our current document
var importedNode = document.importNode(svgDocument.rootElement.firstChild, true);
log("Imported the SVGGElement into our document: " + importedNode + " should be: [object SVGGElement]");
document.getElementById("content").appendChild(importedNode);
}
]]>
</script>
<g id="content" transform="translate(250, 250) rotate(45)">
</g>
</svg>