2016-08-14 52 views

回答

0

getChildByName(字符串名稱)文檔@return the first child having the given name or null, does not recurse 所以,如果元存在它會返回它,如果它不存在,它將返回null。

你可以這樣做:

XmlReader.Element book = element.getChildByName("book"); 
if(book != null) { 
    //Book exists, I can operate on it 
    String content = book.getText(); 
} 
else { 
    //Book doesn't exist 
    Gdx.app.debug("XML","Book does not exist!"); 
} 
相關問題