以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 SVG/GML/VRML/X3D/XAML 』  (http://bbs.xml.org.cn/list.asp?boardid=21)
----  高手来指教(keeponline,edison1024,卷积内核.... 排名不分先后,分来的频率,呵呵)  (http://bbs.xml.org.cn/dispbbs.asp?boardid=21&rootid=&id=28799)


--  作者:落花落叶落飞扬
--  发布时间:3/17/2006 10:30:00 AM

--  高手来指教(keeponline,edison1024,卷积内核.... 排名不分先后,分来的频率,呵呵)
此例通过svg内部的脚步来修改svg
xml文件名:test.xml 内容:
<g id='ext-g'>
   <text id='ext-txt1' x='50' y='50' font-size='36' font-family='Arial'>Test</text>
   <rect id='ext-rct1' x='50' y='100' width='100' height='50' fill='none' stroke='blue'/>
</g>

svg文件名:test.svg 内容:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-flat-20030114.dtd">
<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" onload="init(evt)">
<g id="importNode">
  <!-- import content with xml file is here -->
</g>
<script type="text/javascript">
  <![CDATA[
   function init(evt)
   {
    svgDoc=evt.target.ownerDocument;
    importNode = svgDoc.getElementById('importNode');
    getURL('test.xml', loadedfile);
   }
   function loadedfile(obj)
   {
    if(obj.success)
    {
     var tmpNode = parseXML(obj.content, svgDoc);//将xml文件中的内容转化成SVG片段
     importNode.appendChild(tmpNode);//将片段追加到<g>元素中,作为它的一个子节点
    }
    .....
   }
  ]]>
</script>
</svg>

[color=#FF0000]而此例在htm中取得svg,然后在修改svg内容[/color]
<script language="javascript">
var SVGEmbed = null;
var SVGDocument = null;
var SVGVersion = null;

var templeContent = new ActiveXObject("MSXML2.DOMDocument.3.0");
templeContent.load("test.xml");

function loadTemplet()
{
try
{
  SVGEmbed = document.embeds["SVGEmbed"];//或者用 document.getElementById("SVGEmbed");
  SVGVersion = SVGEmbed.getSVGViewerVersion();
  if(!(SVGVersion.indexOf("Adobe") != -1))return;
  SVGDocument = SVGEmbed.getSVGDocument();
  loadSVG(templeContent);
  //SVGEmbed.window.getURL("test.xml",loadSVG2);
}
catch(e)
{
  alert(e.message);
  //window.location.reload();
}
}
function loadSVG(templeContent)
{
var SVGContent = templeContent.selectSingleNode("//g");
//alert(SVGContent.xml);
var frag = SVGEmbed.window.parseXML(SVGContent.xml,SVGDocument);
//alert(SVGEmbed.window.printNode(frag));
SVGDocument.rootElement.appendChild(frag.firstChild);
}
</script>

我的问题是:在htm获得SVGDocument后,除了红色的SVGDocument.rootElement.appendChild(frag.firstChild)修改svg外,其他有什么办法修改,结点很多时或者得到特定的结点,我用了selectSingleNode,getElementById都不行,不知道怎么回事,请指教!!!


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
38.086ms