Hey Guys,
Today, I experienced a very strange problem, and I did not find any solution for it:
Let's say I have a Xml Document which looks like this:
<RootNode>
<ParentNode>
<Text value="Test" />
<Text value="Tes2t" />
</ParentNode>
<ParentNode>
<Text value="Test" />
<Text value="Tes2t" />
</ParentNode>
</RootNode>
And I have an XSD which describes the above xml. After pulling it through xsd.exe, i got the following classes (only pseudocode, don't have the code with me):
[XmlRoot(Namespace = "http://www.test.com/"]
public class RootNode
{
public ParentNode[] ParentNode { get; set; }
}
[XmlRoot(Namespace = "http://www.test.com/"]
public class ParentNode
{
public Text[] Text { get; set; }
}
[XmlRoot(Namespace = "http://www.test.com/"]
public class Text
{
public string Value { get; set; }
}
Now I try to deserialize the above Xml (as string) using the XmlSerializer to get the object structure.
The main Problem is, that in the Xsd, there are namespaces declared, which are not available in the Xml. I do not have access to the xml source to add the xmlns attributes there, nor do I want to change the automagically created classes from the xsd.exe.
If I use the XmlSerializer without any additional settings, I get an error that he have an error at the beginning of the document (he don't expected a <RootNode xmlns="" node). If I add a RootNodeAttribute to the constructor of the XmlSerializer (described here: http://msdn.microsoft.com/en-us/library/f1wczcys.aspx) then the deserialization runs whithout an exception, but all properties have their default-values / null values).
Does anyone have a hint for me, how I could solve this problem? It don't mind if I respect the xmlns or not, I just want to get the xml data into a C# object ;)
Update 1:
Testing source is here:
https://bitbucket.org/cke/xsdxmldeserializertest/overview[
^]
Update 2:
I ended up in creating a new schema for the XML, because I found out that the given XML does not match the given xsd...
Lots of work waiting for me... ;)
Thanks alot, any help is appreciated!
Chris