Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java org.jdom2.IllegalNameException_Java_Xml_Jdom - Fatal编程技术网

Java org.jdom2.IllegalNameException

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

我使用的是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/XML attributes: XML names cannot contain the character " ".

你不明白什么?我不明白两件事:1根据Javadoc,只有当Element.setAttributes1,s2的第一个参数无效时,你才能遇到这个问题。在这里,问题似乎来自第二个。在我这方面,这段代码执行时没有错误。然而,如果我尝试feature.setAttributeMantic角色,name;相反,我得到了这个错误,这正是预期的行为。你确定你没有推翻这两个论点吗?编辑:我对你的答案投了更高的票,这样你就有足够的声誉在评论中回答。请仔细检查你的错误。我复制/粘贴了你的代码,它对我有效。