[Mono-list] XSD -> classes -> deserialize not so easy after all
Athos Deterious
gwehydd at gmail.com
Tue Nov 15 13:28:47 EST 2011
All mentioned files are located
https://skydrive.live.com/redir.aspx?cid=5bf95d40632ca444&resid=5BF95D40632CA444!315
here
Hi All,
I'm completely new to Web Services and XSD's - I've primarily done 'Linq to
SQL'.
So I got this task of developing a Library application (in MonoTouch).
Sounded easy enough.
I started of by getting the "AlmaMessage.xsd" file and its documentation
"AlmaMessage.doc".
Ok, I did a simple ">xsd AlmaMessage.xsd /classes" and got the
"AlmaMessage.cs" file.
I then made a console project in MonoDevelop and included all the files and
some test data in "Test.xml".
After a few test I made this primitive program :
------------------------------------------------------
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using Schemas; // Namespace in the AlmaMessage.cs file
namespace aTestofXSDtoCS
{
class MainClass
{
public static void Main (string[] args)
{
AlmaMessage am = new AlmaMessage();
XmlSerializer s = new XmlSerializer(typeof(AlmaMessage));
FileStream fs = new FileStream("Test.xml", FileMode.Open);
XmlReader reader = XmlReader.Create(fs);
am = (AlmaMessage) s.Deserialize(reader);
fs.Close();
}
}
}
------------------------------------------------------------------------
After a successful build I tried to run it but got the following :
/[ERROR] FATAL UNHANDLED EXCEPTION: System.InvalidOperationException: There
is an error in XML document. ---> System.InvalidOperationException:
<AlmaMessage xmlns=''> was not expected
at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadRoot
(System.Xml.Serialization.XmlTypeMapping rootMap) [0x00066] in
/private/tmp/monobuild/build/BUILD/mono-2.10.6/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationReaderInterpreter.cs:186
at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadRoot ()
[0x00028] in
/private/tmp/monobuild/build/BUILD/mono-2.10.6/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationReaderInterpreter.cs:87
at System.Xml.Serialization.XmlSerializer.Deserialize
(System.Xml.Serialization.XmlSerializationReader reader) [0x0001c] in
/private/tmp/monobuild/build/BUILD/mono-2.10.6/mcs/class/System.XML/System.Xml.Serialization/XmlSerializer.cs:361
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Deserialize
(System.Xml.Serialization.XmlSerializationReader reader) [0x00064] in
/private/tmp/monobuild/build/BUILD/mono-2.10.6/mcs/class/System.XML/System.Xml.Serialization/XmlSerializer.cs:371
at System.Xml.Serialization.XmlSerializer.Deserialize
(System.Xml.XmlReader xmlReader) [0x0002c] in
/private/tmp/monobuild/build/BUILD/mono-2.10.6/mcs/class/System.XML/System.Xml.Serialization/XmlSerializer.cs:350
at a.MainClass.Main (System.String[] args) [0x00029] in
/Users/jab/Projects/a/a/Main.cs:23
Press any key to continue.../
This is where I got stuck ... no matter what I do I seem to go back to this
error ... now since I don't know much about XSD's, XML or Web Services I
can't get passed this point without more work then I have time for so could
someone help ?
TIA,
Athos Deterious.
--
View this message in context: http://mono.1490590.n4.nabble.com/XSD-classes-deserialize-not-so-easy-after-all-tp4073570p4073570.html
Sent from the Mono - General mailing list archive at Nabble.com.
More information about the Mono-list
mailing list