Oleg,
Although I can work around this problem, I'd really like to get to the
bottom of this... as to why this happens. Here is a sample of the incoming
xml:
<?xml version="1.0"?>
<association xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<fromid>8c4a969b-2aa4-4679-b170-d9f6441f7c6d</fromid>
<fromobjecttypecode>1</fromobjecttypecode>
<toid>df3f306f-19de-4f50-9784-623bf6693fa8</toid>
<toobjecttypecode>2</toobjecttypecode>
<forwardrelation>Parent</forwardrelation>
<backrelation>Parent</backrelation>
<forwardnotes>aaa</forwardnotes>
<backnotes>bbb</backnotes>
</association>
My derived XmlReader replaces the association root node to
association_create - simply returning association_create in place of
association in Name and LocalName properties. And here is how I
deserialize:
StringReader sr = new StringReader(Association);
EntityReader er = new EntityReader(sr, "association",
EntityReader.Mode.Create, Context);
XmlSerializer serializer = new XmlSerializer(typeof(association_create));
association_create associationObj = serializer.Deserialize(er) as
association_create;
And below is the class generated by XSD that XmlSerializer uses to
deserialize:
[System.Xml.Serialization.XmlRootAttribute(Namespac e="", IsNullable=false)]
public class association_create {
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form= System.Xml.Schema.XmlSche
maForm.Unqualified)]
public lookupElement fromid;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form= System.Xml.Schema.XmlSche
maForm.Unqualified)]
public int fromobjecttypecode;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form= System.Xml.Schema.XmlSche
maForm.Unqualified)]
public lookupElement toid;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form= System.Xml.Schema.XmlSche
maForm.Unqualified)]
public int toobjecttypecode;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form= System.Xml.Schema.XmlSche
maForm.Unqualified)]
public string forwardrelation;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form= System.Xml.Schema.XmlSche
maForm.Unqualified)]
public string backrelation;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form= System.Xml.Schema.XmlSche
maForm.Unqualified)]
public string forwardnotes;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form= System.Xml.Schema.XmlSche
maForm.Unqualified)]
public string backnotes;
}
I really appreciate your help on this. Thanks.
Jiho
"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:OY**************@TK2MSFTNGP10.phx.gbl...
Jiho Han wrote:
I am feeding this class to XmlSerializer.Deserialize method. I have a
class that was generated by xsd.exe and it is able to serialize/deserialize
properly if I give it a proper Stream or TextReader. It's only when I
feed it my custom XmlReader it fails.
Well, apparently some namespace issue involved? We've been talking only
about renaming root element on the fly, not about modifying namespace.
The samples you have posted had no namespace.
Without seeing your real XML I can suggest nothing.
--
Oleg Tkachenko [XML MVP, XmlInsider]
http://blog.tkachenko.com