I posted a different flavour of this problem before with no joy. I’m hoping a refactored question will help.
Essentially, i’m loading an XML string into an XDocument then using XDocument.GetReader() to return a XmlReader. From here I’m using a XmlSerializer to deserialise the following XML:
<?xml version='1.0' encoding='UTF-8'?>
<osgb:FeatureCollection
xmlns:osgb='http://www.ordnancesurvey.co.uk/xml/namespaces/osgb'
xmlns:gml='http://www.opengis.net/gml'
xmlns:xlink='http://www.w3.org/1999/xlink'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:schemaLocation='http://www.ordnancesurvey.co.uk/xml/namespaces/osgb http://www.ordnancesurvey.co.uk/xml/schema/v7/OSDNFFeatures.xsd'
fid='GDS-58116-1'>
<gml:description>OS</gml:description>
<gml:boundedBy>
<gml:null>unknown</gml:null>
</gml:boundedBy>
<osgb:queryTime>2009-07-30T02:35:17</osgb:queryTime>
<osgb:queryExtent>
<osgb:Rectangle srsName='osgb:BNG'>
<gml:coordinates>291000.000,92000.000 293000.000,94000.000</gml:coordinates>
</osgb:Rectangle>
</osgb:queryExtent>
</osgb:FeatureCollection>
to this class (generated using XSD)
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://www.ordnancesurvey.co.uk/xml/namespaces/osgb")]
[System.Xml.Serialization.XmlRootAttribute("FeatureCollection", Namespace = "http://www.ordnancesurvey.co.uk/xml/namespaces/osgb", IsNullable = false)]
public partial class FeatureCollectionType : AbstractFeatureCollectionType
{
private System.DateTime queryTimeField;
private GeometryPropertyType queryExtentField;
private System.DateTime queryChangeSinceDateField;
private bool queryChangeSinceDateFieldSpecified;
private FeatureAssociationType[] _featureMemberField;
private BoundingShapeType boundedBy1Field;
// more properties
}
The inner exception shows that: <FeatureCollection xmlns='http://www.ordnancesurvey.co.uk/xml/namespaces/osgb'> was not expected.
I can’t see what the problem it. I don’t need a root node above the collection do I?
I have tested a simplified version (with all properties removed from
FeatureCollectionType), and it didn’t throw at the first element:How are you instantiating
XmlSerializer?