XML Parsing Error: XML or text declaration not at start of entity

XML Parsing Error | Line Number 1, Column 2

How to solve parse error in your first XML file. Given below a simple XML file.

<xml version=”1.0″ encoding=”UTF-8″ ?>

<note>
<to>John</to>

<from>Harry</from>

<heading>Reminder</heading>

<body>Don’t forget me this weekend!</body>

</note>

Copy above XML data to a text file and save the same as XML file.

Sometimes it throws XML Parsing Error: XML or text declaration not at start of entity.

The reason is the empty space at the beginning of the first line. Make sure that there is no space preceding the tag <note>

When this happens the following error is printed on the screen

XML Parsing Error: XML or text declaration not at start of entity
Location: http://localhost/test.xml
Line Number 1, Column 2:
-^

Points to remember when saving XML file:

  1. Make sure no space before starting tag.
  2. Close each tag. For example you need to close tag <to> with </to>.


Buy Laptop | Gaming Laptop | Laptop Not Charging

Leave a Reply

Your email address will not be published. Required fields are marked *