I am currently writing an XML writer/reader. I have it writing to the xml file, now I am attempting to read from it. However, when I do so the following error is thrown and I am not sure why:
'>' is an unexpected token. The expected token is '='. Line 6, position 16. XML reader c#
Please could someone shed some light on this for me?
The XML file:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<assignments>
<assignment>
<ModuleTitle>Internet Programming</ModuleTitle>
<AssignmentTitle>Assignment 01</AssignmentTitle>
<Date Given>11/02/2015</Date Given>
<Date Due>20/02/2015</Date Due>
</assignment>
</assignments>
UPDATE:
The problem was the fact that in some of my tag names I had spaces, which was causing the error.
You have invalid spaces, the following will work:
XElement config = XElement.Parse (
@"<?xml version='1.0' encoding='utf-8' standalone='yes'?>
<assignments>
<assignment>
<ModuleTitle>Internet Programming</ModuleTitle>
<AssignmentTitle>Assignment 01</AssignmentTitle>
<DateGiven>11/02/2015</DateGiven>
<DateDue>20/02/2015</DateDue>
</assignment>
</assignments>");
Please note DateGiven and DateDuewithout spaces.
The spaces are the reason for the error as shown below:

<Date Given> is not a valid XML syntax. Given is supposed to be an attribute with a value, so it should look something like this: <Date Given="true">
Edit to be useful in the future: as @James mentioned, it is just a space in the tag name, which is also invalid in XML.
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