您的位置:程序门 -> web 开发 -> xml/soap



xml属性读取问题


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


xml属性读取问题[已结贴,结贴人:lk829]
发表于:2007-12-06 17:26:36 楼主
<?xml   version="1.0"   encoding="gb2312"   ?>  
<text>
<textinfo>
<position   data="59,82"/>  
<size   data="700,40"   />  
<textblock>
<font   size="15"   weight="200"   typeface="arial"   color="255,255,102"   italic="0"   underline="1"   />  
<text   data="都是一家人,不至于发展成“敌我矛盾”吧!"   />  
<link   data="http://www.baidu.com"   />  
</textblock>
</textinfo>
<textinfo>
<position   data="88,82"   />  
<size   data="700,40"   />  
<textblock>
<font   size="15"   weight="200"   typeface="arial"   color="0,0,204"   italic="0"   underline="1"   />  
<   data="更多请看娱乐频道"   />  
<link   data="changechannel/109666"   />  
</textblock>
</textinfo>
</text>
---------------------------------
要求在html显示
text   为文字说明  
link   为文字链接
主要就是把这显示出来
偶只是个菜鸟   搞拉一天   都解决不了 <textblock> 里的属性值读取不出来     求助

发表于:2007-12-06 17:36:471楼 得分:0
问题是你用什么读,是在哪里读?  
发表于:2007-12-06 17:47:032楼 得分:0
javascript或者vbscript或者dom
发表于:2007-12-07 09:48:433楼 得分:0
xml code
<?xml version="1.0" encoding="gb2312"?> <text> <textinfo> <position data="59,82"/> <size data="700,40"/> <textblock> <font size="15" weight="200" typeface="arial" color="255,255,102" italic="0" underline="1"/> <text data="都是一家人,不至于发展成“敌我矛盾”吧!"/> <link data="http://www.baidu.com"/> </textblock> </textinfo> <textinfo> <position data="88,82"/> <size data="700,40"/> <textblock> <font size="15" weight="200" typeface="arial" color="0,0,204" italic="0" underline="1"/> <text data="更多请看娱乐频道"/> <link data="changechannel/109666"/> </textblock> </textinfo> </text> <?xml version="1.0" encoding="gb2312"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:template match="/"> <table> <xsl:for-each select="//textblock"> <tr> <td> <xsl:value-of select="text/@data"/> </td> <td> <a> <xsl:attribute name="href"><xsl:value-of select="link/@data"/></xsl:attribute> <xsl:value-of select="link/@data"/> </a> </td> </tr> </xsl:for-each> </table> </xsl:template> </xsl:stylesheet>



html code
<html> <head> <meta http-equiv="content-type" content="text/html; charset=gb2312"></head> <body onload="init();"> </body> </html> <script > function init(){ var xml = new activexobject("microsoft.xmldom") xml.async = false xml.load("tmp0000.xml") //alert(xml.xml) var xsl = new activexobject("microsoft.xmldom") xsl.async = false xsl.load("3.xsl") //alert() //guidcontent.innertext = xml.transformnode(xsl); guidcontent.innerhtml = xml.transformnode(xsl); } </script> <div id="guidcontent"></div>

发表于:2007-12-07 11:55:354楼 得分:0
很感谢楼上兄弟的的回复  

现在如果将问题扩展  
position   为元素位置的定位
size   为元素的大小
textblock/font     为元素的样式
textblock/text   为元素文本
textblock/link   为元素文本链接
-----------------
用div来控制元素的定位   不能用xsl  
只能用js或vbs实现

因偶才接触到xml   东西赶的紧  
没有办法   才这样求助  
此贴先给楼上50分
解决问题的另外开帖在给100分  


发表于:2007-12-07 14:32:445楼 得分:0
html code
<%@language="vbscript" codepage="936"%> <!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=gb2312"> <title>untitled document</title> </head> <body> </body> </html> <script language="javascript"> arr={}; var str=""; var xmldoc = new activexobject("microsoft.xmldom"); xmldoc.loadxml('<textinfo><position data="59,82"/><size data="700,40"/><textblock><font size="100" weight="100" typeface="arial" color="255,255,102" italic="0" underline="0"/><text data="都是一家人,不至于发展成“敌我矛盾”吧!"/><link data="http://www.baidu.com"/></textblock></textinfo>'); //alert(xmldoc.documentelement.xml); //gen biao ji var textinfo=xmldoc.selectnodes("//textinfo"); //jiang zi fu chang zhuan huan wei xml dui xiang for (i=0;i<textinfo.length;i++){ var position=textinfo[i].selectsinglenode("position/@data"); var size=textinfo[i].selectsinglenode("size/@data"); var font=textinfo[i].selectsinglenode("textblock/font"); var text=textinfo[i].selectsinglenode("textblock/text/@data"); var link1=textinfo[i].selectsinglenode("textblock/link/@data"); var div1=document.createelement("div"); div1.style.top=position.text.split(",")[0]; div1.style.left=position.text.split(",")[1]; div1.style.width=size.text.split(",")[0]; div1.style.height=size.text.split(",")[1]; div1.style.position="absolute"; for(i=0;i<font.attributes.length;i++){ str=str+font.attributes[i].name+"="+font.attributes[i].text+" " } div1.innerhtml="<a href='"+link1.text+"'><font "+str+">"+text.text+"</font></a>"; document.body.appendchild(div1); } </script>

终于给你弄完了,我不知道为什么我这不能加载xml文件,所以只能用字符串代替,你看看效果
发表于:2007-12-07 17:22:246楼 得分:0
再次感谢楼上热心的帮助

var   textinfo=xmldoc.documentelement.selectnodes("textinfo");     写成这样就可以加载xml文件成功拉

不过始终只能读出一条信息   我想有几条就读出显示几条
我调试了半天   始终不成功
能否在帮我看下
发表于:2007-12-07 19:47:007楼 得分:100
jscript code
for(j=0;j<font.attributes.length;j++){ str=str+font.attributes[j].name+"="+font.attributes[j].text+" " }

因为重复定义了变量,把i该成j好啦


快速检索

最新资讯
热门点击