I have 2 Xml's which I want to deserialize into 1 class as the innerxml is same, I want to remove the Scehma ie the namespaces and want to change rootname before deserialising.
XML 1
<MyXMLTest1 xsi:schemaLocation="abc1" xmlns:xsi="abc12" xmlns="abc123">
<element1>xml1hi</element1>
</MyXMLTest1>
XML 2
<MyXMLTest2 xsi:schemaLocation="abc2" xmlns:xsi="abc23" xmlns="abc234">
<element1>xml1hi</element1>
</MyXMLTest2>
Class
[System.Xml.Serialization.XmlRoot("MyXMLTest", IsNullable=true)]
public partial class MyXMLTest{
public string element1 {get;set;}
}
Method
var xDocument = XDocument.Load(@"myxml.xml"); string myxmlstring = xDocumnet.ToString();
var reader = new StringReader(myxmlstring );
var serializer = new XmlSerializer(typeof(MyXMLTest));
var instance = (MyXMLTest)serializer.Deserialize(reader);
//I'm getting error on the last line that <MyXMLTest1 xsi:schemaLocation="abc1" xmlns:xsi="abc12" xmlns="abc123"> was not expected
How Can I then ignore the namespaces and the Root Name for any uploaded Xml?
Thanks