标记必须格式良好 [英] The markup must be well-formed

查看:184
本文介绍了标记必须格式良好的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我要说我是SAX和Java的新手。

First off, let me say I am a new to SAX and Java.

我正在尝试从格式不正确的XML文件中读取信息。

I am trying to read information from an XML file that is not well formed.

当我尝试使用SAX或DOM Parser时,我收到以下错误:

When I try to use the SAX or DOM Parser I get the following error in response:

The markup in the document following the root element must be well-formed.

这是我设置XML文件的方式:

This is how I set up my XML file:

<format type="filename" t="13241">0;W650;004;AG-Erzgeb</format>
<format type="driver" t="123412">001;023</format>
   ...

我是否可以强制SAX或DOM解析XML文件,即使它们是是不是格式良好的XML?

Can I force the SAX or DOM to parse XML files even if they are not well formed XML?

感谢您的帮助。非常感激。
Haythem

Thank you for your help. Much appreciated. Haythem

推荐答案

最好的办法是使XML格式良好,可能需要预处理一下。在这种情况下,您可以通过在(甚至是可选的)上放置XML声明并提供根元素(不是可选的)来实现这一点,如下所示:

Your best bet is to make the XML well-formed, probably by pre-processing it a bit. In this case, you can achieve that simply by putting an XML declaration on (and even that's optional) and providing a root element (which is not optional), like this:

<?xml version="1.0"?>
<wrapper>
    <format type="filename" t="13241">0;W650;004;AG-Erzgeb</format>
    <format type="driver" t="123412">001;023</format>
</wrapper>

我已经随意选择了根元素的名称wrapper;它可以是你喜欢的任何东西。

There I've arbitrarily picked the name "wrapper" for the root element; it can be whatever you like.

这篇关于标记必须格式良好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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