Error: XML document structures must start and end within the same entity
Asked Answered
S

4

13

I am new to XML and getting the below error:

Error: XML document structures must start and end within the same entity

Input 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>
Stulin answered 9/5, 2016 at 13:25 Comment(0)
P
9

Your XML is not well-formed. In general, this error indicates that something is wrong with the range of the start and end tags.

In particular in your case, you have a stray s in one of the closing access2 tags:

    <access2>115AL<s/access2>

Here is your XML with the problem resolved; it is now well-formed (and indented to improve readability):

<?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>
Passus answered 9/5, 2016 at 14:36 Comment(0)
S
1

The accepted answer is certainly correct, however - since this question is easily googlable by error message - I have another weird reason of this error: (I was confused at first for a while since my XML was well-formed)

The error may happen when underlying stream is closed. In my case I had a SequenceInputStream of multiple fragments of XML which was mistakenly closed in try-with-resources block but XML reader on top of this SequenceInputStream was still open. The error happens on attempt of reading StAX event beyond the boundary of two concatenated streams.

Slung answered 30/7 at 21:5 Comment(0)
H
0

If your xml is well formed, as fixed in kjhughes answer, you can always run xmllint to prettify it as:

[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 ~]$ 

Just as an FYI.

Of course, xmllint is primarily for validating a document.

Honourable answered 19/6, 2020 at 4:25 Comment(0)
I
0

I spend a lot of time on this still, I cannot able to find file where this issue is available and finally, This work for me

android {
    buildTypes {
        release {
            shrinkResources false
        }
    }
}

Note: If necessary, you can disable resource shrinking by adding

Indoctrinate answered 9/8, 2022 at 6:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.