2011-06-27 26 views
0

我遇到了一個類似於很多人的問題,但我無法得到它。我正在用我的Android應用程序創建一個xml文檔,但是我看不懂它:我得到錯誤"Only one root element is allowed"XML和Android:只允許一個根元素?

這是我的XML,我真的不明白爲什麼它不起作用,因爲我認爲我尊重W3C規則。

我只是沒有填充應用程序的所有文件。

<?xml version='1.0' encoding='UTF-8' standalone='no' ?> 
<client> 
    <civilite1>Monsieur</civilite1> 
    <nom1>Nom</nom1> 
    <prenom1>Prénom</prenom1> 
    <adresseactuelle1></adresseactuelle1> 
    <codepostal1></codepostal1> 
    <ville1></ville1> 
    <telprof1></telprof1> 
    <telport1></telport1> 
    <email2></email2> 
    <civilite2>Monsieur</civilite2> 
    <nom2>Nom</nom2> 
    <prenom2>Prénom</prenom2> 
    <adresseactuelle2></adresseactuelle2> 
    <codepostal2></codepostal2> 
    <ville2></ville2> 
    <telprof2></telprof2> 
    <telport2></telport2> 
    <email2></email2> 
    <adresseconstruction></adresseconstruction> 
    <codepostalconstruction></codepostalconstruction> 
    <villeconstruction></villeconstruction> 
    <notes></notes> 
</client> 

這是我的Java代碼來打開文件:

try { 
     fichier = new File(path+nomDuFichier); 
     factory = DocumentBuilderFactory.newInstance(); 
     builder = factory.newDocumentBuilder(); 
     document = builder.parse(fichier); 
     document.getDocumentElement().normalize(); 
     NodeList liste = document.getElementsByTagName("client"); 
    } catch (Exception e) { 
     Log.e("Erreur : ", e.getMessage()); 
    } 
+0

我也收到這個錯誤。 –

回答

1

出於某種原因,這個工程:

Document doc = documentBuilder.parse(fichier.toURI().toString()); 

我想接收一個文件可能有一個錯誤的解析方法在裏面。