I'm receiving an error message while deserializing an XML document into an object. How can this be solved?
There is an error in XML document (5, 14)
This is the XML document:
<?xml version="1.0"?>
<Customer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<FirstName>Khaled</FirstName>
<LastName>Marouf</LastName>
</Customer><?xml version="1.0"?>
<Customer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<FirstName>Faisal</FirstName>
<LastName>Damaj</LastName>
</Customer><?xml version="1.0"?>
<Customer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<FirstName>Lara</FirstName>
<LastName>Khalil</LastName>
</Customer>
Your XML document is in fact three documents. A valid XML document must have only one root node for instance. Also, XML declarations are not valid inside the document.
This is valid XML (XML declaration comes first, one root element):
<?xml version="1.0"?>
<Customer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<FirstName>Khaled</FirstName>
<LastName>Marouf</LastName>
</Customer>
This is not valid XML (multiple root elements, xml declaration inside document):
<?xml version="1.0"?>
<Customer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<FirstName>Khaled</FirstName>
<LastName>Marouf</LastName>
</Customer><?xml version="1.0"?>
<Customer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<FirstName>Faisal</FirstName>
<LastName>Damaj</LastName>
</Customer>
To expand on Fredrik Mörk's answer, the clue is in the error message: (5, 14)
refers to the row number and column number where the parser thinks the problem is. Here, that points at the second XML declaration, which as has been mentioned is not allowed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With