首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > XML SOAP >

svg中通过parseXML()得到的node如何用appendChild()加不上去呢

2012-03-27 
svg中通过parseXML()得到的node怎么用appendChild()加不上去呢?1-------------------外层svg文件---------

svg中通过parseXML()得到的node怎么用appendChild()加不上去呢?
1-------------------外层svg文件-----------
<?xml   version= "1.0 "   encoding= "utf-8 "?>
<svg   id= "svg "   width= "800 "   height= "600 "   xmlns:xlink= "http://www.w3.org/1999/xlink "   onload= "getContentInFile(); ">
<script>
<![CDATA[
plat=document.getElementById( "plat ");

function   getContentInFile(){
xmlDoc   =   getURL( 'test.svg ',fn)
}

function   fn(xmlDoc)
{
  var   x   =   parseXML(xmlDoc.content)
  s=x.getElementsByTagName( "svg ").item(0);
  nodeList=s.childNodes;
 
        for(i=0;i <nodeList.length;i++){
var   node=nodeList.item(i);

if(node.nodeType==1){
alert(node);
alert(node.nodeName);
plat.appendChild(node);//here   alert "wrong   document "   error   message
}
        }
}
]]>

</script>
<g   id= "plat ">
  <rect     x= "0 "   y= "60 "   width= "720 "   height= "450 "   fill= "white "   stroke= "gray "   stroke-width= "1 "/>
    </g>
</svg>
2----------------------------test.svg   file-------------------------------
<?xml   version= "1.0 "   encoding= "utf-8 "?>  
<svg   width= "100% "   height= "100% "   xmlns:xlink= "http://www.w3.org/1999/xlink ">
<rect   id= "backRect "     x= "0 "     y= "60 "     width= "720 "     height= "450 "     fill= "white "     stroke= "gray "     stroke-width= "1 "     />  
<circle   cx= "202 "     cy= "312 "     r= "43 "     stroke= "red "     stroke-width= "1 "     fill= "blue "     />  
</svg>

如果把plat.appendChild(node);去掉,就一切正常!
我是想把test.svg文件的各个element加到外层svg文件中!也就是提取指定svg文件中的所有node

多谢呀!!!!!!!!!

[解决办法]
昨天的例子

<?xml version= "1.0 " encoding= "utf-8 "?>
<svg id= "svg " width= "800 " height= "600 " onload= "getContentInFile(); ">
<script>
<![CDATA[
function getContentInFile(){
xmlDoc = getURL( 'test.svg ',fn)
}
function fn(xmlDoc)
{
var x = parseXML(xmlDoc.content,document)
document.getElementById( "plat ").appendChild(x.firstChild)
}
]]>

</script>
<g id= "plat ">
<rect x= "0 " y= "60 " width= "720 " height= "450 " fill= "white " stroke= "gray " stroke-width= "1 "/>
</g>
</svg>

热点排行