以文本方式查看主题

-  计算机科学论坛  (http://bbs.xml.org.cn/index.asp)
--  『 XML源码及示例(仅原创和转载) 』  (http://bbs.xml.org.cn/list.asp?boardid=32)
----  一个具有挑战性的难题!希望大家给出解决方案!!!  (http://bbs.xml.org.cn/dispbbs.asp?boardid=32&rootid=&id=19467)


--  作者:rfgweb
--  发布时间:6/9/2005 10:07:00 PM

--  一个具有挑战性的难题!希望大家给出解决方案!!!
对xml字符串进行解析处理。

文本域1:
<?xml version="1.0" encoding="GB2312"?>
<feature xmlns:v="urn:schemas-microsoft-com:vml">
<region>
<style id="R01">
<v:fill on="true" color="#ffff00" opacity="30%" />
</style>
</region>
</feature>

文本域2:
<?xml version="1.0"?>
<v:rect style="width:100;height:100" />

文本域3:

要求:
为“文本域2”中的xml添加子节点:
1、先将“文本域1”中的v:fill节点克隆到“文本域2”中的xml的

v:rect节点下。
2、再新建一个v:stroke节点,该节点有on、color和weight三个属

性;
将新建的节点也加到“文本域2”中的xml的v:rect节点下。
3、在页面上的效果是:当点击“提交”按钮时,在“文本域3”中

能看到以下结果:
<?xml version="1.0"?>
<v:rect style="width:100;height:100" >
<v:stroke on="true" color="#3366FF" weight="2pt"/>
<v:fill on="true" color="#ffff00" opacity="30%" />
</v:rect>


希望大家给出参考答案来讨论啊!


--  作者:rfgweb
--  发布时间:6/9/2005 10:20:00 PM

--  希望各位看看下面这段代码什么地方需要改进!!劳驾各位!先谢谢了!!
<html>

<head>
var xmlstring1="
<?xml version="1.0" encoding="GB2312"?>
<feature xmlns:v="urn:schemas-microsoft-com:vml">
        <region>
                <style id="R01">
                       <v:fill on="true" color="#ffff00" opacity="30%" />
                </style>
        </region>
</feature>
";
   
var xmlstring2="
<?xml version="1.0"?>
<v:rect style="width:100;height:100"/>
";

<script language="jscript">
<!--
var xmldom=new ActiveXObject("Microsoft.XMLDOM");
xmldom.async="false";

function shix(){                                           //解析xml
var xmldom=new ActiveXObject("Microsoft.XMLDOM");
xmldom.async="false";
xmldom.loadXML(xmlstring1);

var p=xmlDocument.getElementsByTagName(style);
var f=p.firstChild;                                        //复制v:fill节点
f.cloneNode(false);

var xmldom=new ActiveXObject("Microsoft.XMLDOM");
xmldom.async="false";
xmldom.loadXML(xmlstring2);

var r=xmlDocument.documentElement;                         //插入到v:rect节点下
r.appendChild(f);

var s=xmlDocument.createNode(1,"v:stroke","");             //新建v:stroke节点
var on=xmlDocument.createAttribute("true");
var color=xmlDocument.createAttribute("#ffff00");
var opacity=xmlDocument.createAttribute("30%");
r.insertBefore(s,f);                                          //插到v:fill节点前面

var xmlvalue=xmlDocument.documentElement;
alert(xmlvalue.xml);

}
//-->
</script>
</head>

<body>

<form name="form1">
<b>文本域1: </b>
<br>
<textarea name="showtext1"    rows="7"  cols="90">   
<?xml version="1.0" encoding="GB2312"?>
<feature xmlns:v="urn:schemas-microsoft-com:vml">
        <region>
                <style id="R01">
                       <v:fill on="true" color="#ffff00" opacity="30%" />
                </style>
        </region>
</feature>

</textarea>

<br>
<b> 文本域2:</b>
<br>
<textarea name="showtext2"   rows="5"  cols="90">
<?xml version="1.0"?>
<v:rect style="width:100;height:100"/>

</textarea>

<br>
<b> 文本域3:</b>
<br>
<textarea name="showtext3"  rows="10"  cols="90">
<?xml version="1.0"?>
<v:rect style="width:100;height:100">
  <v:stroke on="true"  color="#3366FF"  weight="2pt"/>
  <v:fill on="true" color="#ffff00" opacity="30%" />
</v:rect>
</textarea>
<br>
<input type="button"  name="submit"  value="提交"  onclick="document.form1.showtext3.display()">

</form>

</body>
</html>

什么地方需要改进,就是结果不能显示到文本域3中。该怎么办啊???


--  作者:jx27
--  发布时间:6/16/2005 8:08:00 PM

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