I have the following code which I think should work but it just returns NULL on all 4 properties:
[XmlRoot("ArrayOfSomething")]
public class ArrayOfSomething
{
[XmlAttribute()]
public string Id { get; set; }
[XmlAttribute()]
public string Bool { get; set; }
[XmlAttribute()]
public string Title { get; set; }
[XmlAttribute()]
public string Something { get; set; }
}
public class NamespaceIgnorantXmlTextReader : XmlTextReader
{
public NamespaceIgnorantXmlTextReader(System.IO.TextReader reader) : base(reader) { }
public override string NamespaceURI
{
get { return ""; }
}
}
public void Run()
{
XmlSerializer serializer = new XmlSerializer(typeof(ArrayOfSomething));
StringReader sr = new StringReader("<ArrayOfSomething xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" ><Item><Id>0</Id><Bool>false</Bool><Title>Some text</Title><Something/></Item><Item><Id>0</Id><Bool>false</Bool><Title>Some text 2</Title><Something/></Item><Item><Id>0</Id><Bool>false</Bool><Title>Some text 3</Title><Something/></Item><Item><Id>0</Id><Bool>false</Bool><Title>Some text 4</Title><Something/></Item></ArrayOfSomething>");
NamespaceIgnorantXmlTextReader XMLWithoutNamespace = new NamespaceIgnorantXmlTextReader(sr);
var s = (ArrayOfSomething)serializer.Deserialize(XMLWithoutNamespace);
}
And to make it easier for you to read the xml:
<ArrayOfSomething xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Item>
<Id>0</Id>
<Bool>false</Bool>
<Title>Some text</Title>
<Something/>
</Item>
<Item>
<Id>0</Id>
<Bool>false</Bool>
<Title>Some text 2</Title>
<Something/>
</Item>
<Item>
<Id>0</Id>
<Bool>false</Bool>
<Title>Some text 3</Title>
<Something/>
</Item>
<Item>
<Id>0</Id>
<Bool>false</Bool>
<Title>Some text 4</Title>
<Something/>
</Item>
</ArrayOfSomething>
Why is s always returning null for all properties? I have used XMLAttribute on all properties and all methods are public. I started by using the XSD way but it gave me the same result so I tried to make it as above to do it in an easy way.