错误:解析 XML 时出错:标签不匹配
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29979679/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
error: Error parsing XML: mismatched tag
提问by Harrison
I am getting this error:
我收到此错误:
Error parsing XML: mismatched tag.
解析 XML 时出错:标签不匹配。
If anyone knows how to fix this, can you please let me know what I'm missing, thank you.
如果有人知道如何解决这个问题,请告诉我我缺少什么,谢谢。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/android" >
<Button
android:id="@+id/btnChangeImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change Image" >
</LinearLayout>
回答by Guffa
The closing tags for the <ImageView>and <Button>tags are missing.
<ImageView>和<Button>标签的结束标签丢失。
You can add a /at the end of the tags to make them self-closing:
您可以/在标签的末尾添加一个以使其自动关闭:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/android" />
<Button
android:id="@+id/btnChangeImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change Image" />
</LinearLayout>
回答by E LaRoche
Agree with the above answers, but I think the answers can be added to by showing you a simple way to debug this yourself for the future (teach a man to fish...).
同意上述答案,但我认为可以通过向您展示一种简单的方法来为将来自己调试(教一个人钓鱼......)来添加答案。
Modern browsers have XML parsers built in. Open your original file using Internet Explorer. It gives this error message:
现代浏览器内置了 XML 解析器。使用 Internet Explorer 打开您的原始文件。它给出了这个错误信息:
End tag 'LinearLayout' does not match the start tag 'Button'.
Once you close the Button node, save the file and open it again. It gives you this error:
关闭 Button 节点后,保存文件并再次打开它。它给你这个错误:
End tag 'LinearLayout' does not match the start tag 'ImageView'.
Close that tag, save and re-open file. The well formed XML renders in the browser. While normally I an not a big proponent of IE, it gives a better error message than Chrome, and it allows you to collapse and expand each level of nested XML, which is really helpful for more complex XML. I hope this technique helps you out in the future.
关闭该标签,保存并重新打开文件。格式良好的 XML 在浏览器中呈现。虽然通常我不是 IE 的大力支持者,但它提供了比 Chrome 更好的错误消息,并且它允许您折叠和展开嵌套 XML 的每一级,这对于更复杂的 XML 确实很有帮助。我希望这项技术可以帮助你在未来。
回答by Shane Van Wyk
Need to close the Buttonand ImageViewTags.
需要关闭Button和ImageView标签。
For every Tag / Node / Element you open, you need to also close them.
对于您打开的每个标签/节点/元素,您还需要关闭它们。
For example: if you open with <Tag>you need to close with </Tag>or add a slash at the end of the tag like this: <Tag />
例如:如果你打开<Tag>你需要关闭</Tag>或在标签的末尾添加一个斜杠,如下所示:<Tag />
Solution to your problem is bellow:
您的问题的解决方案如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/android" /> <!-- This one here -->
<Button
android:id="@+id/btnChangeImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change Image" /> <!-- This one here -->
</LinearLayout>
OR
或者
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/android" >
</ImageView> <!-- This one here -->
<Button
android:id="@+id/btnChangeImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change Image" >
</Button> <!-- This one here -->
</LinearLayout>

![xml 如何在 XSLT 中使用 <![CDATA[]]>?](/res/img/loading.gif)