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

jdom中调用setAttribute(Sring key,Sring value)时,如果key中带有冒号,则报错解决办法

2012-01-22 
jdom中调用setAttribute(Sring key,Sring value)时,如果key中带有冒号,则报错例如:Element testElement

jdom中调用setAttribute(Sring key,Sring value)时,如果key中带有冒号,则报错
例如: 
Element testElement = new Element("test"); 
testElement.setAttribute("xsi:type","IP_TTTTT"); 

则会报如下错误: 
Exception in thread "AWT-EventQueue-0" org.jdom.IllegalNameException: The name "xsi:type" is not legal for JDOM/XML attributes: Attribute names cannot contain colons. 

各位XDJM们有没有碰到过类似的问题,又如何解决?


还有,生成XML文件时,如在根节点中生成了命名空间,为什么子元素中有个xmlns=""的.如
<SCL xmlns="http://www.iec.ch/61850/2003/SCL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.iec.ch/61850/2003/SCL SCL.xsd">
  <Header xmlns="" id="xxxxxx" name="Name" version="1" revision="1" />
  <Communication xmlns="">
  ......
  </Communication >
</SCL>


[解决办法]
转义一下吧

热点排行