473,320 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Cannot deserialize XML even though it validates against generated XSD file.

I'm getting acquainted with the whole XML/XSD thing, and I've run into
a wall. I have a tree of objects that I deserialize from XML for
configuration reasons. I have generated XSD from the classes for this
tree. I have made an XML file that validates against that XSD.
However, when I try to deserialize from the XML file, I get complaints
that

System.InvalidOperationException was unhandled
Message="There is an error in XML document (11, 6)."

Now, this is using a validating reader based on XSD that was generated
from the very classes I'm trying to deserialize. The focus of the
problem is this: I use a lot of collections where the collection
contains the base, abstract class and the types within the collection
are of numerous derived classes. As a result, the names of the
XmlArray elements are the name of the abstract class, with the names of
the derived classes held in the xsi:type attribute. It seems that when
the XML Deserializer runs into these XSI:type attributes (the first of
which is at 11,6), it throws a hissy-fit.

Thus, the problem:

<MergeModules>
<MergeModule xsi:type ="MergeFiles"></MergeModule >
</MergeModules>

where MergeModule is my abstract class, "MergeFiles" is my derived
class, and both MergeModules and MergeFiles are valid XSD types that
were generated from the aforementioned assembly classes.

What gives? Is there some trick to cajole the XML Deserializer to use
my schema to help it figure out which XSD type corresponds to which
DotNet type? Or do I have to go through the rigamarole of manually
listing every single type that could exist in every single array that
holds a MergeModule? Some of the busiwork of that can be used with
XmlAttributeOverrides, but then I'm pretty sure that XSD.EXE will not
be aware of the procedurally-added attributes, and thus I'd have to go
through a whole different rigamarole with setting up an XSD
schema-exporter within my app.

Do I just have to suck it up and accept it that the statement (from the
XSD.EXE documentation):
"""
Classes to XSD
Generates an XML schema from a type or types in a runtime assembly
file. The generated schema defines the XML format used by
System.XML.Serialization.XMLSerializer.
"""
is false? Or is there some workaround, maybe by some bizarre
application of the SOAP deserializer?

Oct 18 '06 #1
1 2437
Found it. The base class must be decorated with XMLIncludeAttributes
referencing the derived classes. One of those many things that seems
like it ought to be default behaviour.... I wouldn't be so frustrated
if all the XSD validation hadn't gone without a hitch - heck, it was
even autocompleting these values for me.
Martin Z wrote:
I'm getting acquainted with the whole XML/XSD thing, and I've run into
a wall. I have a tree of objects that I deserialize from XML for
configuration reasons. I have generated XSD from the classes for this
tree. I have made an XML file that validates against that XSD.
However, when I try to deserialize from the XML file, I get complaints
that

System.InvalidOperationException was unhandled
Message="There is an error in XML document (11, 6)."

Now, this is using a validating reader based on XSD that was generated
from the very classes I'm trying to deserialize. The focus of the
problem is this: I use a lot of collections where the collection
contains the base, abstract class and the types within the collection
are of numerous derived classes. As a result, the names of the
XmlArray elements are the name of the abstract class, with the names of
the derived classes held in the xsi:type attribute. It seems that when
the XML Deserializer runs into these XSI:type attributes (the first of
which is at 11,6), it throws a hissy-fit.

Thus, the problem:

<MergeModules>
<MergeModule xsi:type ="MergeFiles"></MergeModule >
</MergeModules>

where MergeModule is my abstract class, "MergeFiles" is my derived
class, and both MergeModules and MergeFiles are valid XSD types that
were generated from the aforementioned assembly classes.

What gives? Is there some trick to cajole the XML Deserializer to use
my schema to help it figure out which XSD type corresponds to which
DotNet type? Or do I have to go through the rigamarole of manually
listing every single type that could exist in every single array that
holds a MergeModule? Some of the busiwork of that can be used with
XmlAttributeOverrides, but then I'm pretty sure that XSD.EXE will not
be aware of the procedurally-added attributes, and thus I'd have to go
through a whole different rigamarole with setting up an XSD
schema-exporter within my app.

Do I just have to suck it up and accept it that the statement (from the
XSD.EXE documentation):
"""
Classes to XSD
Generates an XML schema from a type or types in a runtime assembly
file. The generated schema defines the XML format used by
System.XML.Serialization.XMLSerializer.
"""
is false? Or is there some workaround, maybe by some bizarre
application of the SOAP deserializer?
Oct 18 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
2
by: IanT | last post by:
Hi I need help with my approach to validating de-serialized XML received via webservice. Hopefully someone can point me to sources detailing best practice for the following. I agreed a...
7
by: Wayne Brantley | last post by:
I have found what appears to be an error in streaming with Datasets. It causes an error of 'Cannot find relation 0' when recreating the dataset from a stream. Here is how you reproduce it. ...
3
by: Jeff Richardson | last post by:
This is a repost from the InfoPath news group. Hi, I am writing a SharePoint application that works with InfoPath forms. When a user submits a completed InfoPath form to a forms library my code...
0
by: svestin | last post by:
Hi all! I have run into some strange behaviour in XmlSerializer. (.net 2.0) 1. I have a normal (but quite large) XSD-schema and an XML-file that is valid. 2. I use xsd.exe to generate...
2
by: Vivek | last post by:
In an application which uses an XML file, I wish to use XmlSchemaValidator class to validate this file against the XSD file.. In the example of msdn, (...
0
by: Vivek | last post by:
In an application which uses an XML file, I wish to use XmlSchemaValidator class to validate this file against the XSD file.. In the example of msdn, (...
2
by: mudge | last post by:
Hi, I'm getting some very strange problems with some C# code. We're running an ASP.NET application on a local server in a DMZ. If I access it using the internal address, the application works...
9
by: =?Utf-8?B?ai5hLiBoYXJyaW1hbg==?= | last post by:
Hi, I have a schema that has an optional element, fieldTag4000Field. If the element is omitted from the XML request, when it is deserialized, it will be null when I check it - which is fine. ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.