parser error : XML declaration allowed only at the start of the document



I have a xml file which contains multiple declarations like the following



<?xml version="1.0" encoding="UTF-8"?>
<root>
<node>
<element1>Stefan</element1>
<element2>42</element2>
<element3>Shirt</element3>
<element4>3000</element4>
</node>
</root>

<?xml version="1.0" encoding="UTF-8"?>
<root>
<node>
<element1>Damon</element1>
<element2>32</element2>
<element3>Jeans</element3>
<element4>4000</element4>
</node>
</root>


when i tried to load the xml with



$data = simplexml_load_file("testdoc.xml") or die("Error: Cannot create object");


then it gives me the following error



Warning: simplexml_load_file(): testdoc.xml:11: parser error : XML declaration allowed only at the start of the document in C:\xampp\htdocs\crea\services\testxml.php on line 3

Warning: simplexml_load_file(): <?xml version="1.0" encoding="UTF-8"?> in C:\xampp\htdocs\crea\services\testxml.php on line 3

Warning: simplexml_load_file(): ^ in C:\xampp\htdocs\crea\services\testxml.php on line 3

Warning: simplexml_load_file(): testdoc.xml:12: parser error : Extra content at the end of the document in C:\xampp\htdocs\crea\services\testxml.php on line 3

Warning: simplexml_load_file(): <root> in C:\xampp\htdocs\crea\services\testxml.php on line 3

Warning: simplexml_load_file(): ^ in C:\xampp\htdocs\crea\services\testxml.php on line 3
Error: Cannot create object


please let me know how to parse this xml or how to split it into no of xml files so that i can read. The file size is around 1 gb.


No comments:

Post a Comment