Is the following format correct for XML? I am trying to parse the file in PHP using simplexml_load_file but keep receiving an error stating that there is ‘Extra content at the end of the document on line 3’.
Here is the XML file:
<?xml version="1.0"?>
<title>Test File</title>
<data>
<record id="1">
<department>
<name>ACME</name>
<number>5</number>
</dep_name>
<floor>
<name>ACME Floor</name>
<number>5</number>
</floor>
</record>
</data>
An XML document must consist of a single root element and its descendants.
Your first start tag is
<title>. It has a text node as its sole descendent. You then have a</title>tag which ends the root element and thus the document.<data>and everything following it is therefore an error.You probably want to create a new element type to be the root (and wrap the entire document, excluding the XML declaration, with it).
You also need to correct either
<department>or</dep_name>as you appear to have changed the name of the element halfway through creating it.You should run your code through a validator or a lint, as that will highlight errors.