У меня проблема похожая на многих людей, но я не могу ее решить. Я создаю XML-документ с помощью своего приложения для Android, но не могу его прочитать: я получаю сообщение об ошибке "Only one root element is allowed"
.
Вот мой 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());
}