I have been given an XML file and an XSD file. I am trying to validate the XML against the XSD and then, using Serialization
, load the the XML into an object.
I have the validation working as expected but when I try to DeserializeDocToObj
I get the following error.
There was an error deserializing the object of type
Aaa.Bbb.Common.DataTypes.SurveyGroup. Processing instructions
(other than the XML declaration) and DTDs are not supported.
Line 1, position 2.
I have no idea what this means and all I have read is not really helping.
The header in the XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.mydomain.co.uk/srm/mscc"
targetNamespace="http://www.mydomain.co.uk/srm/mscc"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:element name="SurveyGroup">
The header in the XML
<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="mscc4_cctv.xsl"?>
<SurveyGroup xmlns="http://www.mydomain.co.uk/srm/mscc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.mydomain.co.uk/srm/mscc
http://www.mydomain.co.uk/srm/schemas/mscc4_cctv.xsd">
<Survey>
Deserialization Code:
public T DeserializeDocToObj(string fileLocation)
{
T returnObj;
using (FileStream reader = new FileStream(fileLocation, FileMode.Open, FileAccess.Read))
{
DataContractSerializer ser = new DataContractSerializer(typeof(T));
returnObj = (T)ser.ReadObject(reader);
}
return returnObj;
}
Any help greatly appreciated