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());
}
我也收到这个错误。 –