2012-10-15 55 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