Java org.jdom2.IllegalNameException
我使用的是jdom2,当尝试使用空格设置元素值时,它会弹出错误 部分代码如下所示:Java org.jdom2.IllegalNameException,java,xml,jdom,Java,Xml,Jdom,我使用的是jdom2,当尝试使用空格设置元素值时,它会弹出错误 部分代码如下所示: Element feature = new Element("feature"); feature.setAttribute("name", "semantic role"); 错误: Exception in thread "main" org.jdom2.IllegalNameException: The name "semantic role" is not legal for JDOM/XM
Element feature = new Element("feature");
feature.setAttribute("name", "semantic role");
错误:
Exception in thread "main" org.jdom2.IllegalNameException: The name "semantic role" is not legal for JDOM/XML attributes: XML names cannot contain the character " ".
你不明白什么?我不明白两件事:1根据Javadoc,只有当Element.setAttributes1,s2的第一个参数无效时,你才能遇到这个问题。在这里,问题似乎来自第二个。在我这方面,这段代码执行时没有错误。然而,如果我尝试feature.setAttributeMantic角色,name;相反,我得到了这个错误,这正是预期的行为。你确定你没有推翻这两个论点吗?编辑:我对你的答案投了更高的票,这样你就有足够的声誉在评论中回答。请仔细检查你的错误。我复制/粘贴了你的代码,它对我有效。