2012-10-15 53 views

回答

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); 
    } 
} 
+0

这种方式,它显示在控制台罚款,当我尝试读取它的价值是返回null – Aswan

+0

作品,也是:System.out.println(((Attribute)attrs.get(0))。getValue()); –

+0

这是好的,但属性是动态的,我不能硬编码 – Aswan