SVG:Namespace: Difference between revisions

1,821 bytes removed ,  3 December 2005
wiki.m.o is for planning, MDC is for current state, so redirecting to MDC doc
(wiki.m.o is for planning, MDC is for current state, so redirecting to MDC doc)
Line 1: Line 1:
= Declare namespaces for SVG and XLink=
#REDIRECT [[http://developer.mozilla.org/en/docs/SVG:Namespaces_Crash_Course]]
 
The namespace declaration for SVG is required. If you don't specify it, nothing will be rendered. The XLink namespace is required if you use <use/>, <image/>, <a/> ...
 
*The SVG namespace: http://www.w3.org/2000/svg
*The XLink namespace: http://www.w3.org/1999/xlink
 
A simple SVG file may look like this:
 
<?xml version="1.0"?>
<svg xmlns="http://www.w3.org/2000/svg"
    xmlns:xlink="http://www.w3.org/1999/xlink">
  <title>title of drawing</title>
</svg>
 
== Declare DOCTYPE for SVG ==
 
Similarly, declaring a correct DOCTYPE for .svg files may be useful for DTD validation. This can catch some, but not all errors and is a useful supplement to well-formedness checking.
 
''There are uncomfirmed reports that  an SVG file without namespace and incorrect doctype did work in Adobe SVG, but with the namespace added it didn’t work, until the DOCTYPE was corrected as well.''
 
The doctype for SVG 1.1 Full is:
 
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
 
= use namespace-aware methods in javascript=
 
when using js, make sure you use the namespace aware methods like:
 
*getElementsByTagNameNS()
*createElementNS()
*setAttributeNS()
*getAttributeNS()
*...
 
svg elements are in the svg namespace. Unqualified svg attributes are in the null namespace. Qualified attributes are in whatever namespace their prefix id declared as - so for example xlink:href is in the XLink namespace, http://www.w3.org/1999/xlink.
For example, to dynamically create an <image> element, do it like this:
 
const svgns="http://www.w3.org/2000/svg";
const xlinkns="http://www.w3.org/1999/xlink";
var newIM=document.createElementNS(svgns,"image");
newIM.setAttributeNS(null,"width",100);
newIM.setAttributeNS(null,"height",100);
newIM.setAttributeNS(xlinkns,"href","bild2.png");
 
 
== Links ==
 
[[SVG:Home Page]]
Confirmed users, Bureaucrats and Sysops emeriti
969

edits