【问题标题】:Error: XML document structures must start and end within the same entity错误:XML 文档结构必须在同一实体内开始和结束
【发布时间】:2016-05-09 13:25:38
【问题描述】:

我是 XML 新手,遇到以下错误:

错误:XML 文档结构必须在相同的范围内开始和结束 实体

输入 XML:

<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
<test>
<access1>113AL</access1>
<access2>119AL</access2>
</test>
<test>
<access2>115AL<s/access2>
<access3>116AL</access3>
</test>
<test>
<access4>118AL</access4>
<access5>119AL</access5>
</test>
<copies>
<test2>
<access>113AL</access>
<Copy>Y</Copy>
</test2>
<test2>
<access>113AX</access>
<Copy>N</Copy>
</test2>
</copies>
</root>

【问题讨论】:

    标签: xml


    【解决方案1】:

    您的 XML 格式不正确。 一般来说,这个错误表示开始和结束标签的范围有问题。

    特别是在您的情况下,您在结束 access2 标记之一中有一个流浪 s

        <access2>115AL<s/access2>
    

    这是解决问题的 XML;它现在格式正确(并且为了提高可读性而缩进):

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <root>
      <test>
        <access1>113AL</access1>
        <access2>119AL</access2>
      </test>
      <test>
        <access2>115AL</access2>
        <access3>116AL</access3>
      </test>
      <test>
        <access4>118AL</access4>
        <access5>119AL</access5>
      </test>
      <copies>
        <test2>
          <access>113AL</access>
          <Copy>Y</Copy>
        </test2>
        <test2>
          <access>113AX</access>
          <Copy>N</Copy>
        </test2>
      </copies>
    </root>
    

    【讨论】:

      【解决方案2】:

      如果您的 xml 格式正确,如 kjhughes 答案中所修复,您可以随时运行 xmllint 将其美化为:

      [nsaunders@rolly ~]$ 
      [nsaunders@rolly ~]$ cat foo.xml 
      <?xml version="1.0" encoding="ISO-8859-1"?>
      <root>
      <test>
      <access1>113AL</access1>
      <access2>119AL</access2>
      </test>
      <test>
      <access2>115AL</access2>
      <access3>116AL</access3>
      </test>
      <test>
      <access4>118AL</access4>
      <access5>119AL</access5>
      </test>
      <copies>
      <test2>
      <access>113AL</access>
      <Copy>Y</Copy>
      </test2>
      <test2>
      <access>113AX</access>
      <Copy>N</Copy>
      </test2>
      </copies>
      </root>
      [nsaunders@rolly ~]$ 
      [nsaunders@rolly ~]$ xmllint --format foo.xml --output foo.xml
      [nsaunders@rolly ~]$ 
      [nsaunders@rolly ~]$ cat foo.xml 
      <?xml version="1.0" encoding="ISO-8859-1"?>
      <root>
        <test>
          <access1>113AL</access1>
          <access2>119AL</access2>
        </test>
        <test>
          <access2>115AL</access2>
          <access3>116AL</access3>
        </test>
        <test>
          <access4>118AL</access4>
          <access5>119AL</access5>
        </test>
        <copies>
          <test2>
            <access>113AL</access>
            <Copy>Y</Copy>
          </test2>
          <test2>
            <access>113AX</access>
            <Copy>N</Copy>
          </test2>
        </copies>
      </root>
      [nsaunders@rolly ~]$ 
      

      仅供参考。

      当然,xmllint 主要用于验证文档。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-12-12
        • 1970-01-01
        • 1970-01-01
        • 2017-12-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多