我創建了一些自定義svg屬性,但還想通過svg validator測試。自定義svg元素或屬性的D3和SVG命名空間是否有效?
只見D3 > Namespace page,以前How can I specify a custom XML/SVG namespace with D3.js?,因此處理如下:
// d3.ns.prefix.geo = "http://www.example.com/boundingbox/";
// d3.ns.prefix.inkscape = "http://www.inkscape.org/namespaces/inkscape";
// SVG injection:
var width = 600;
var svg = d3.select("#hook").append("svg")
.attr("name", "Country's_name_administrative_map_\(2015\)")
.attr("id", "Country_s_name")
.attr("width", width)
.attr(':xmlns:geo','http://www.example.com/boundingbox/')
.attr(':xmlns:inkscape','http://www.inkscape.org/namespaces/inkscape')
.attr(":xmlns:cc","http://creativecommons.org/ns#");
// Tags:
svg.append(":geo:g")
.attr(':xmlns:geo','http://www.example.com/boundingbox/')
.attr(":geo:id","geo")
.attr(':geo:syntax', "WSEN bounding box in decimal degrees")
.attr(':geo:west', WEST)
.attr('geo:south', SOUTH)
.attr(':geo:east', EAST)
.attr(':geo:north', NORTH)
.attr(':geo:title', title);
農產品:
<?xml version="1.0" 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"
name="Country's_name_administrative_map_(2015)"
id="Country_s_name"
xmlns:geo="http://www.example.com/boundingbox/"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:cc="http://creativecommons.org/ns#"
width="600"
height="579.2009758421691"
version="1.1">
<defs xmlns="http://www.w3.org/1999/xhtml">
<style type="text/css"><![CDATA[
svg { border: 1px solid rgb(100, 100, 100); }]]>
</style>
</defs>
<geo:g xmlns:geo="http://www.example.com/boundingbox/"
geo:id="geo"
geo:syntax="WSEN bounding box in decimal degrees"
geo:west="-5.8"
south="41"
geo:east="10"
geo:north="51.5"
geo:title="Country's name" />
<defs><pattern id="hash2_4" width="6" h…
…
</svg>
我仍然得到所有的錯誤(larger image):
第一種類型的錯誤與自定義的<geo:g … >
元素本身有關,可見於上面。 第二種類型的錯誤與自定義屬性相關,例如geo:west="…"
或inkscape:group="…"
,由於早期的xmlns
聲明,我預計該屬性有效。
我走錯路了嗎? 如何通過d3js使自定義屬性有效?
編輯:最小jsfiddle提供手推車輸出的演示。
您使用的是HTML文檔或XML(XHTML或SVG)?自定義名稱空間和'xmlns'屬性僅在XML中有效。在HTML文檔中使用SVG的非官方方式是使用HTML'data- *'屬性。但是,它可能仍然會失敗一個驗證器。 – AmeliaBR 2015-02-10 05:17:57
* Ting !!! *這是一個很好的線索。 :) – Hugolpz 2015-02-10 11:51:10
使用xml。我的文件頭以'<?xml version =「1.0」standalone =「no」?><!DOCTYPE svg PUBLIC「開頭 - // W3C // DTD SVG 1.1 // EN」「http://www.w3 .org/Graphics/SVG/1.1/DTD/svg11.dtd「>