Android:XML解析:org.w3c.dom.DOMException:仅允许一个根元素 [英] Android: XML parsing: org.w3c.dom.DOMException: Only one root element allowed

查看:263
本文介绍了Android:XML解析:org.w3c.dom.DOMException:仅允许一个根元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试解析xml文件.但是我得到这个错误: org.w3c.dom.DOMException:仅允许一个根元素 在此行:

I am trying to parse an xml file. But i get this error: org.w3c.dom.DOMException: Only one root element allowed at the line:

        Document doc = dBuilder.parse(getAssets().open("myfile.xml"));

请帮助我解决这个问题.

Please help me solve this.

谢谢.

推荐答案

您必须只有一个根,这意味着您必须只有一个标签,且标签包围所有标签.例如,您可以用<root></root>

You must have only one root, it means you must have only once a tag that surround every all tags. For example you can surround all your tags by <root></root>

此外,请尝试使用xml验证程序来验证xml文件,以查看xml是否格式错误.

Also, try to validate your xml file with an xml validator in order to see if your xml is malformed.

这篇关于Android:XML解析:org.w3c.dom.DOMException:仅允许一个根元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆