使用jdom解析特殊字符属性的问题
前
< tag xml:lang="123" >
此案例getAttributes()
方法返回null
有没有解决方法可以解决这个问题。
答案 0 :(得分:2)
对我来说没有问题:
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);
}
}
答案 1 :(得分:1)
您可能需要设置名称空间,请检查http://cs.au.dk/~amoeller/XML/programming/jdomexample.html