其实我用的是SVG文件,其实就是个XML类型文件呀。 相关语句定义如下: var newNode=null; //用于接收不同node类型的值 dnode是“var xml = new ActiveXObject("Microsoft.XMLDOM");”通过函数A(xml)传的XML形参。问题没有解决,谢谢楼上两位
... ... case 4: //NODE_CDATA_SECTION newNode = svgdoc.createCDATASection(snode.childNodes(i).nodeValue); ... ...dnode.appendChild(newNode); ... ...根据“The CDATASection node can appear as the child of the DocumentFragment, EntityReference, and Element nodes.”的解释,当newNode为CDATASection类型的节点时是和Document类型的dnode无法结合的
你是怎么赋值这2个的?需要是个完整的节点啊
相关语句定义如下:
var newNode=null; //用于接收不同node类型的值
dnode是“var xml = new ActiveXObject("Microsoft.XMLDOM");”通过函数A(xml)传的XML形参。问题没有解决,谢谢楼上两位
if(typeof(newNode)=="object")
dnode.appendChild(newNode);
newNode本身就是"object",我试过还是不行。
function saveIt(){
//debugger;
var xml = new ActiveXObject("MSXML2.DOMDocument");
var svgdoc = document.embeds["map"].getSVGDocument();
copyNode(svgdoc,xml,svgdoc,xml)
xml.save("test.svg");
}//使用的函数库test.Js
//debugger;
function copyNode(snode,dnode,svg,svgdoc){
var i=0;
var newNode = null;
for(i=0; i<snode.childNodes.length; i++){
switch(snode.childNodes(i).nodeType){
case 1: //NODE_ELEMENT
newNode = svgdoc.createElement(snode.childNodes(i).nodeName);
copyAttributes(snode.childNodes(i), newNode);
break;
case 2: //NODE_ATTRIBUTE
newNode = svgdoc.createAttribute(snode.childNodes(i).nodeName);
break;
case 3: //NODE_TEXT
newNode = svgdoc.createTextNode(snode.childNodes(i).nodeValue);
break;
case 4: //NODE_CDATA_SECTION
newNode = svgdoc.createCDATASection(snode.childNodes(i).nodeValue);
break;
case 5: //NODE_ENTITY_REFERENCE
newNode = svgdoc.createEntityReference(snode.childNodes(i).nodeName);
break;
case 6: //NODE_ENTITY
break;
case 7: //NODE_PROCESSING_INSTRUCTION
newNode = svgdoc.createProcessingInstruction("xml", snode.childNodes(i).nodeValue);
break;
case 8: //NODE_COMMENT
newNode = svgdoc.createComment(snode.childNodes(i).nodeValue);
break;
case 9: //NODE_DOCUMENT
break
case 10: //NODE_DOCUMENT_TYPE
break;
case 11: //NODE_DOCUMENT_FRAGMENT
newNode = svgdoc.createDocumentFragment();
break;
case 12: //NODE_NOTATION
break;
default:
}
if (newNode != null){
dnode.appendChild(newNode);
copyNode(snode.childNodes(i), newNode, svg, svgdoc);
}
}
}
function copyAttributes(sNode, dNode){
var i=0;
for (i=0; i < sNode.attributes.length; i++){
if (sNode.attributes(i).nodeName != "xmlns:xmlns"
&& sNode.attributes(i).nodeName.substr(0, 2) != "on"
)
dNode.setAttribute(sNode.attributes(i).nodeName, sNode.attributes(i).nodeValue);
}
}
//</script>“map”是一个xml引入文件的名称,test.xml文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20000303 Stylable//EN" "http://www.w3.org/TR/2000/03/WD-SVG-20000303/DTD/svg-20000303-stylable.dtd">
<svg xml:space="preserve" width="600" height="440" onload="init()" enableZoomAndPanControls="false">
<style type="text/css">
<![CDATA[
@font-face{font-family:'Impact';src:url(../fonts/impact.cef)}
@font-face{font-family:'ComicSansMS';src:url(../fonts/comic.cef)}
@font-face{font-family:'Myriad-Bold';src:url(../fonts/myriad-bold.cef)}
@font-face{font-family:'Palatino-Bold';src:url(../fonts/palatino-bold.cef)}
@font-face{font-family:'Myriad-Roman';src:url(../fonts/myriad-roman.cef)}
@font-face{font-family:'AdobeCorpID-MyriadBdScn';src:url(../fonts/myriadBdScn.cef)}
@font-face{font-family:'Kaufmann';src:url(../fonts/kaufmann.cef)}
]]>
</style>
<g id="bgControl">
<image id="background" xlink:href="images/blank.gif" style="display:none" width="600" height="440" onclick="deSelector()" image-rendering="optimizeSpeed"/>
</g>
<!-- *** don't add anything below this line *** -->
<g id="drawBoard" onmouseover="onSel(evt)" onmouseout="offSel()" onclick="selector(evt)">
</g>
<!-- Pre Select Box -->
<g id="preSelBox" style="fill:none; stroke:blue; display:none">
<rect x="0" y="0" width="5" height="5"/>
</g>
<!-- Select Box -->
<g id="selBox" style="display:none;">
<g id="boxes" onmousedown="movePrep(evt)" onkeydown="keys(evt)">
<rect id="selBoxFill" x="20" y="20" width="50" height="50"
style="fill:white; opacity:0;"/>
<rect id="selBoxOutline" x="20" y="20" width="50" height="50"
style="fill:none; stroke:blue; stroke-width:1;"/>
</g>
<g id="boxTools">
<g id="tool_1" style="fill:blue;stroke:blue;">
<g transform="rotate(180) translate(-20,-20)
scale(.7)" style="stroke:blue;fill:blue;"
onmousedown="rotatePrep(evt)">
<rect style="fill:white; stroke:none; opacity:0;"
x="0" y="0" width="20" height="20"/>
<g id="rotate_1">
<path style="fill:none;stroke-width:2;" d="M13.7,5c0,4.9-3.9,8.8-8.8,8.8"/>
<path d="M8.5,5.1L13.6,0l5.1,5.1H8.5z"/>
<path d="M5.1,19.1L0,13.9l5.1-5.1v10.3z"/>
</g>
</g>
<rect id="handle_1" x="18" y="18" width="5" height="5"
onmousedown="editElemPrep(evt)"/>
</g>
<g id="tool_2" style="fill:blue;stroke:blue;">
<g transform="translate(70,5)" style="stroke:blue;">
<g onclick="raiseElem()">
<rect id="u_1" style="fill:white; stroke:none; opacity:0;"
x="-2" y="-1" width="10" height="10"/>
<path id="up_1" d="M3.7,1v2.6h2.5v1.1H3.7v2.7H2.5V4.7H0V3.6h2.5V1h1.2z"/>
</g>
<path d="M6.4,8.7L9,0h1.2L7.6,8.7H6.4z"/>
<g onclick="lowerElem()">
<rect id="d_1" style="fill:white; stroke:none; opacity:0;"
x="8" y="-1" width="10" height="10"/>
<path id="down_1" d="M15.7,3.2v1.6h-4.2V3.2h4.2z"/>
</g>
</g>
<rect id="handle_2" x="68" y="18" width="5" height="5"
onmousedown="editElemPrep(evt)"/>
</g>
<g id="tool_3" style="fill:blue;stroke:blue;">
<g transform="translate(5,77)" style="stroke:blue;">
<g onclick="raiseElem()">
<rect id="u_2" style="fill:white; stroke:none; opacity:0;"
x="-2" y="-1" width="10" height="10"/>
<path id="up_2" d="M3.7,1v2.6h2.5v1.1H3.7v2.7H2.5V4.7H0V3.6h2.5V1h1.2z"/>
</g>
<path d="M6.4,8.7L9,0h1.2L7.6,8.7H6.4z"/>
<g onclick="lowerElem()">
<rect id="d_2" style="fill:white; stroke:none; opacity:0;"
x="8" y="-1" width="10" height="10"/>
<path id="down_2" d="M15.7,3.2v1.6h-4.2V3.2h4.2z"/>
</g>
</g>
<rect id="handle_3" x="18" y="68" width="5" height="5"
onmousedown="editElemPrep(evt)"/>
</g>
<g id="tool_4" style="fill:blue;stroke:blue;">
<g transform="translate(72,72) scale(.7)"
style="stroke:blue;fill:blue;"
onmousedown="rotatePrep(evt)">
<rect style="fill:white; stroke:none; opacity:0;"
x="0" y="0" width="20" height="20"/>
<g id="rotate_2">
<path style="fill:none;stroke-width:2;" d="M13.7,5c0,4.9-3.9,8.8-8.8,8.8"/>
<path d="M8.5,5.1L13.6,0l5.1,5.1H8.5z"/>
<path d="M5.1,19.1L0,13.9l5.1-5.1v10.3z"/>
</g>
</g>
<rect id="handle_4" x="68" y="68" width="5" height="5"
onmousedown="editElemPrep(evt)"/>
</g>
</g>
</g>
<!-- end Select Box -->
<!-- start cursors -->
<g id="crosshair" style="display:none">
<line x1="0" y1="-5" x2="0" y2="5" style="stroke:black" />
<line x1="-5" y1="0" x2="5" y2="0" style="stroke:black" />
</g>
<!-- end cursors -->
<!-- start Drawing Canvas -->
<g onmousemove="moveCursor(evt)" onmousedown="buttonDown(evt)"
onmouseup="buttonUp()" onmouseover="onCanvas()"
onmouseout="offCanvas()" onclick="popper()"
onkeydown="keys(evt)">
<rect id="canvas" x="0" y="0" width="600" height="440"
style="fill:white; opacity:0; display:none"/>
</g>
<!-- end Drawing Canvas -->
<!-- mouse handling rect -->
<rect id="handler" x="0" y="0" width="600" height="440"
style="fill:white; stroke:none; opacity:0; display:none"
onmousemove="moveHandler(evt)" onmouseup="upHandler()"
onkeydown="keys(evt)" onmouseout="upHandler()"/>
<!-- end mouse handling rect -->
<!-- map framing -->
<rect id="bg" x="0" y="0" width="600" height="440"
style="fill:none; stroke:black;stroke-width:3;display:none"/>
<!-- end map framing -->
</svg>
求助中。
(上面test.xml其实是test.svg,就是xml类型的文件)
case 4: //NODE_CDATA_SECTION
newNode = svgdoc.createCDATASection(snode.childNodes(i).nodeValue);
... ...dnode.appendChild(newNode);
... ...根据“The CDATASection node can appear as the child of the DocumentFragment, EntityReference, and Element nodes.”的解释,当newNode为CDATASection类型的节点时是和Document类型的dnode无法结合的
如果是个标准的节点样式,应该能够append.如果不是 添加会报错的. 看来不光判断它是object就完事了 再判断它是不是节点.比如createAttribute返回一个属性,
估计就不能被appendchild了 以上为本人估计
查找资料+缥缈无边=郁闷中ing再次感谢大家!