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

superling 2007-10-18 07:21:53
例如:
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>
...全文
183 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
superling 2007-10-19
  • 打赏
  • 举报
回复
???
grubbyfan 2007-10-18
  • 打赏
  • 举报
回复
转义一下吧

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧