views:

37

answers:

4

I have noticed that there is no document.write in SVG.

Currently I'm looking for a similar function .

Unfortunatley I couldn't find a website that lists all the functions related or supported by the SVG DOM (for eg. related to the document object).

Do you know any online resources where I can find SVG documentation, especially related to scriptin (something similar to a JAVADOC).

+1  A: 

The svg spec from w3c lists the functions/properties that are specified (but I'm not sure if all browsers are implementing the spec correct)

Nikolaus Gradwohl
Thanks for you answer. I found this website when googling, but I couldn't find the functions related to "document"...
Andrei Ciobanu
+2  A: 

You can't use document.write since SVG is XML, not tag soup.

If you want to import a full XML node, you either have to do it by hand or use the standard DOM importNode method.

For example, if you retrieve an XML node from AJAX, first use the responseXML to parse the response as XML, then import it with the document.importNode method so that you can use it whithin your SVG document and insert it with a standard DOM method (appendChild or insertBefore).

Tangui
Do you have idea how can I remove all nodes first, and then add what i need, by using importNode ?
Andrei Ciobanu
Yes. The replaceChild method ! If you can read french (or even if you can't, just look at the examples), you should read http://svground.free.fr/dom.php#clonageHere is the signature :myparentnode.replaceChild(newDomElement, DOMNodeToReplace).You can easily grab the parent node by using the parentNode property.Eg. : daddy = document.getElementById('nodeToReplace').parentNode;
Tangui
+1  A: 

As already mentioned XMLHttpRequest is an option.

Another one is the (non-w3c standard) DOMParser interface which is supported well enough by all browsers except IE, and can be used to implement something similar to document.write in script.

Yet another option is the HTML5 methods innerHTML/outerHTML (do note that older browsers will try to parse the strings as HTML4, which won't work, and there are differences in how xml is parsed depending e.g on the document mimetype).

If we go on, there's DOM 3 Load & Save and the parseXML method defined in SVG Tiny 1.2.

Erik Dahlström
+2  A: 

Much of the standard DOM API you use in HTML pages also works in SVG. The W3C DOM specification is a good place to start, but you may also want to look at w3 schools DOM reference and tutorials.

For all of the SVG-specific DOM interfaces, I think the best reference is the SVG specification. Each section has a subsection called "DOM interfaces" which describes precisely what you're looking for.

echo-flow