Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/306.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 Jdom解析器无法识别特殊字符属性_Java_Jdom - Fatal编程技术网

Java Jdom解析器无法识别特殊字符属性

Java Jdom解析器无法识别特殊字符属性,java,jdom,Java,Jdom,使用jdom解析特殊字符属性时出现问题 前 这种情况下getAttributes()方法返回null 是否有任何解决方案来解决此问题。对我来说没有问题: public class TestJdom { public static void main(String[] args) throws JDOMException, IOException { String xmlString = "<test><tag xml:lang=\"123\"></t

使用jdom解析特殊字符属性时出现问题


这种情况下
getAttributes()
方法返回
null


是否有任何解决方案来解决此问题。

对我来说没有问题:

public class TestJdom
{
  public static void main(String[] args) throws JDOMException, IOException {
    String xmlString = "<test><tag xml:lang=\"123\"></tag></test>";
    SAXBuilder builder = new SAXBuilder();

    StringReader stringReader = new StringReader(new String(xmlString
        .getBytes()));

    Document doc = builder.build(stringReader);
    List<?> attrs = doc.getRootElement().getChild("tag").getAttributes();
    System.out.println(attrs);
  }
}
公共类TestJdom
{
公共静态void main(字符串[]args)抛出jdomeexception、IOException{
字符串xmlString=“”;
SAXBuilder=新SAXBuilder();
StringReader StringReader=新StringReader(新字符串(xmlString
.getBytes());
文档文档=builder.build(stringReader);
List attrs=doc.getRootElement().getChild(“标记”).getAttributes();
系统输出打印项次(属性);
}
}

您可能需要设置名称空间,请检查

是否可以显示一些解析代码?示例标记:通过解析代码,我指的是java jdom调用。这样,当我尝试读取值时,它在控制台中显示得很好,并且返回空值:System.out.println((属性)attrs.get(0)).getValue();在解析其值之前,我必须检查属性是否存在。我的示例清楚地表明getAttributes()在示例xml标记上工作正常。那么你到底有什么问题?
public class TestJdom
{
  public static void main(String[] args) throws JDOMException, IOException {
    String xmlString = "<test><tag xml:lang=\"123\"></tag></test>";
    SAXBuilder builder = new SAXBuilder();

    StringReader stringReader = new StringReader(new String(xmlString
        .getBytes()));

    Document doc = builder.build(stringReader);
    List<?> attrs = doc.getRootElement().getChild("tag").getAttributes();
    System.out.println(attrs);
  }
}