473,624 Members | 2,685 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Strange problem when deserializing! (code include, long!)

Hi,

I implemented a composite pattern which should be serializable to xml.
After spending some time in the newsgroups, i finally managed
serializing, even with utf-8 instead of utf-16, which causes ie
problems. But when deserializing the xml into the object structure,
the following exception is beeing thrown:

There is an error in XML document (3, 701).

Does anybody know how to bypass/solve this problem?

Code below (forget about toXml - I tried to generate the Xml-structure
on my own, but deserializing didn't work either)

Thanks in advance.

Thomas

the Composite Pattern ist implemented as follows:

public abstract class Suchkriterium
{
protected string sqlString;

public Suchkriterium() {}

public abstract string SqlString {get; set;}

public abstract string toXml();

}

public class Suchstring : bee2bee.edb.dal .suche.Suchkrit erium
{

public Suchstring() { this.sqlString = ""; }

public Suchstring(stri ng sqlString)
{
this.sqlString = sqlString;
}

public override string SqlString
{
get
{
return sqlString;
}
set
{
sqlString = value;
}
}

public override string toXml() {
return "<Suchstrin g xmlns:xsd=\"htt p:www.w3.org/2001/XMLScheme\" \n
xmlns:xsi=\"htt p:www.w3.org/2001/XMLScheme-instance\">\n<s qlString>" +
this.sqlString + "</sqlString>";
}
}

public abstract class Verknuepfung :
bee2bee.edb.dal .suche.Suchkrit erium
{
protected Suchkriterium rechterKnoten;
protected Suchkriterium linkerKnoten;
public Verknuepfung ()
{
rechterKnoten = null;
linkerKnoten = null;
}

public Suchkriterium RechterKnoten
{
get
{
return rechterKnoten;
}
set
{
rechterKnoten = value;
}
}
public Suchkriterium LinkerKnoten
{
get
{
return linkerKnoten;
}
set
{
linkerKnoten = value;
}
}

// toXml von linken und rechtem knoten
public override string toXml()
{
string s = "<" + this.GetType(). Name;
s += " xmlns:xsd=\"htt p:www.w3.org/2001/XMLScheme\" \n
xmlns:xsi=\"htt p:www.w3.org/2001/XMLScheme-instance\">\n<L inkerKnoten>";
s += this.linkerKnot en.toXml() +
"</LinkerKnoten>\n <RechterKnoten> ";
s += this.rechterKno ten.toXml() + "</RechterKnoten></";
s += this.GetType(). Name + ">";
return s;
}
}

public class NotIn : bee2bee.edb.dal .suche.Verknuep fung
{

public NotIn()
{
linkerKnoten = null;
rechterKnoten = null;
}

public override string SqlString
{
get
{
if (linkerKnoten != null && rechterKnoten != null)
{
// hier werden die zwei untergeordneten Verknuepfungen mit NOT IN
verbunden
// funktioniert nur unter der Annahme, dass die Primärschlüssel
der Tabellen 'id' heissen
return "(SELECT id FROM (" + linkerKnoten.Sq lString + ") tbl_" +
System.DateTime .Now.Ticks + " WHERE id NOT IN (" +
rechterKnoten.S qlString + "))";
}
else
{
throw new bee2bee.edb.exc eptions.dbSuchk riteriumExcepti on("bee2bee.edb .dal.suche.NotI n:
Mindestens einer der beiden Knoten ist null.");
}
}
set
{
throw new bee2bee.edb.exc eptions.dbSuchk riteriumExcepti on("Der
SqlString eines NotIn-Operators wird berechnet. Er kann nicht gesetzt
werden.");
}
}
}

public class Union : bee2bee.edb.dal .suche.Verknuep fung
{
public Union()
{
linkerKnoten = null;
rechterKnoten = null;
}

public override string SqlString
{

get
{
if (linkerKnoten == null && rechterKnoten == null)
{
throw new bee2bee.edb.exc eptions.dbSuchk riteriumExcepti on("bee2bee.edb .dal.suche.Unio n:
Beide Kinder des Union-Operators sind null.");
}
else if (linkerKnoten != null && rechterKnoten != null)
{

return "(SELECT id FROM ((" + linkerKnoten.Sq lString + ") UNION
(" + rechterKnoten.S qlString + ")) tbl_" + System.DateTime .Now.Ticks +
")";
}
else if (linkerKnoten == null)
{
return rechterKnoten.S qlString;
}
else
{
return linkerKnoten.Sq lString;
}
}
set
{
throw new bee2bee.edb.exc eptions.dbSuchk riteriumExcepti on("Der
SqlString eines Union-Operators wird berechnet. Er kann nicht gesetzt
werden.");
}
}
}
Property for (de-)serializing:

=============== =============== =============== =============== ====

public suche.Suchkrite rium Suchkriterium
{
get
{
// deserialisiere xmlinhalt -> suchkriterium
// benutze dabei die Wrapper-Klasse XmlSuchkriteriu m, da
Suchkriterium nicht direkt serialisiert werden kann
Type [] extraTypes = new Type[4];
extraTypes[0] = typeof(suche.No tIn);
extraTypes[1] = typeof(suche.Su chstring);
extraTypes[2] = typeof(suche.Un ion);
extraTypes[3] = typeof(suche.Ve rknuepfung);

XmlSerializer s = new XmlSerializer(s uchkriterium.Ge tType(),
extraTypes);
StringReader sr = new StringReader(xm linhalt);
XmlTextReader xr = new XmlTextReader(s r);
Console.Out.Wri teLine(xmlinhal t);
try
{
Console.Out.Wri teLine(s.CanDes erialize(xr));
suchkriterium = (suche.Suchkrit erium)s.Deseria lize(xr);
}
catch (Exception e)
{
Console.Out.Wri teLine(e.ToStri ng());
}

return suchkriterium;
}
set
{
suchkriterium = value; // setze die Objektreferenz

Type [] extraTypes = new Type[4];
extraTypes[0] = typeof(suche.No tIn);
extraTypes[1] = typeof(suche.Su chstring);
extraTypes[2] = typeof(suche.Un ion);
extraTypes[3] = typeof(suche.Ve rknuepfung);
XmlSerializer s = new XmlSerializer(s uchkriterium.Ge tType(),
extraTypes); // instanziiere XmlSerializier für Benutzung mit
XmlSuchkriteriu m

MemoryStream mem = new MemoryStream();
StreamWriter pobjStreamWrite r = new StreamWriter(me m, new
System.Text.UTF 8Encoding());

try
{
s.Serialize(pob jStreamWriter, suchkriterium); // just do
it.
}
catch (System.Xml.Xml Exception ex)
{
Console.Out.Wri teLine(ex.Messa ge);
}

mem.Position = 0;
xmlinhalt = new StreamReader(me m).ReadToEnd();

}
}

=============== =============== =============== =============== ====
Nov 11 '05 #1
1 1849
Is the IE problem say something along the lines of you may not change
encoding?

You may be enclosing utf-8 text inside utf-16 or using another encoding.

I would like to see the original xml document that you were having problems
with IE.

Could you attach a copy and send it to the group?

Joe Feser

"Thomas" <th************ ***@bee2bee.biz > wrote in message
news:19******** *************** ***@posting.goo gle.com...
Hi,

I implemented a composite pattern which should be serializable to xml.
After spending some time in the newsgroups, i finally managed
serializing, even with utf-8 instead of utf-16, which causes ie
problems. But when deserializing the xml into the object structure,
the following exception is beeing thrown:

There is an error in XML document (3, 701).

Does anybody know how to bypass/solve this problem?

Code below (forget about toXml - I tried to generate the Xml-structure
on my own, but deserializing didn't work either)

Thanks in advance.

Thomas

the Composite Pattern ist implemented as follows:

public abstract class Suchkriterium
{
protected string sqlString;

public Suchkriterium() {}

public abstract string SqlString {get; set;}

public abstract string toXml();

}

public class Suchstring : bee2bee.edb.dal .suche.Suchkrit erium
{

public Suchstring() { this.sqlString = ""; }

public Suchstring(stri ng sqlString)
{
this.sqlString = sqlString;
}

public override string SqlString
{
get
{
return sqlString;
}
set
{
sqlString = value;
}
}

public override string toXml() {
return "<Suchstrin g xmlns:xsd=\"htt p:www.w3.org/2001/XMLScheme\" \n
xmlns:xsi=\"htt p:www.w3.org/2001/XMLScheme-instance\">\n<s qlString>" +
this.sqlString + "</sqlString>";
}
}

public abstract class Verknuepfung :
bee2bee.edb.dal .suche.Suchkrit erium
{
protected Suchkriterium rechterKnoten;
protected Suchkriterium linkerKnoten;
public Verknuepfung ()
{
rechterKnoten = null;
linkerKnoten = null;
}

public Suchkriterium RechterKnoten
{
get
{
return rechterKnoten;
}
set
{
rechterKnoten = value;
}
}
public Suchkriterium LinkerKnoten
{
get
{
return linkerKnoten;
}
set
{
linkerKnoten = value;
}
}

// toXml von linken und rechtem knoten
public override string toXml()
{
string s = "<" + this.GetType(). Name;
s += " xmlns:xsd=\"htt p:www.w3.org/2001/XMLScheme\" \n
xmlns:xsi=\"htt p:www.w3.org/2001/XMLScheme-instance\">\n<L inkerKnoten>";
s += this.linkerKnot en.toXml() +
"</LinkerKnoten>\n <RechterKnoten> ";
s += this.rechterKno ten.toXml() + "</RechterKnoten></";
s += this.GetType(). Name + ">";
return s;
}
}

public class NotIn : bee2bee.edb.dal .suche.Verknuep fung
{

public NotIn()
{
linkerKnoten = null;
rechterKnoten = null;
}

public override string SqlString
{
get
{
if (linkerKnoten != null && rechterKnoten != null)
{
// hier werden die zwei untergeordneten Verknuepfungen mit NOT IN
verbunden
// funktioniert nur unter der Annahme, dass die Primärschlüssel
der Tabellen 'id' heissen
return "(SELECT id FROM (" + linkerKnoten.Sq lString + ") tbl_" +
System.DateTime .Now.Ticks + " WHERE id NOT IN (" +
rechterKnoten.S qlString + "))";
}
else
{
throw new bee2bee.edb.exc eptions.dbSuchk riteriumExcepti on("bee2bee.edb .dal.suche.NotI n
: Mindestens einer der beiden Knoten ist null.");
}
}
set
{
throw new bee2bee.edb.exc eptions.dbSuchk riteriumExcepti on("Der
SqlString eines NotIn-Operators wird berechnet. Er kann nicht gesetzt
werden.");
}
}
}

public class Union : bee2bee.edb.dal .suche.Verknuep fung
{
public Union()
{
linkerKnoten = null;
rechterKnoten = null;
}

public override string SqlString
{

get
{
if (linkerKnoten == null && rechterKnoten == null)
{
throw new bee2bee.edb.exc eptions.dbSuchk riteriumExcepti on("bee2bee.edb .dal.suche.Unio n
: Beide Kinder des Union-Operators sind null.");
}
else if (linkerKnoten != null && rechterKnoten != null)
{

return "(SELECT id FROM ((" + linkerKnoten.Sq lString + ") UNION
(" + rechterKnoten.S qlString + ")) tbl_" + System.DateTime .Now.Ticks +
")";
}
else if (linkerKnoten == null)
{
return rechterKnoten.S qlString;
}
else
{
return linkerKnoten.Sq lString;
}
}
set
{
throw new bee2bee.edb.exc eptions.dbSuchk riteriumExcepti on("Der
SqlString eines Union-Operators wird berechnet. Er kann nicht gesetzt
werden.");
}
}
}
Property for (de-)serializing:

=============== =============== =============== =============== ====

public suche.Suchkrite rium Suchkriterium
{
get
{
// deserialisiere xmlinhalt -> suchkriterium
// benutze dabei die Wrapper-Klasse XmlSuchkriteriu m, da
Suchkriterium nicht direkt serialisiert werden kann
Type [] extraTypes = new Type[4];
extraTypes[0] = typeof(suche.No tIn);
extraTypes[1] = typeof(suche.Su chstring);
extraTypes[2] = typeof(suche.Un ion);
extraTypes[3] = typeof(suche.Ve rknuepfung);

XmlSerializer s = new XmlSerializer(s uchkriterium.Ge tType(),
extraTypes);
StringReader sr = new StringReader(xm linhalt);
XmlTextReader xr = new XmlTextReader(s r);
Console.Out.Wri teLine(xmlinhal t);
try
{
Console.Out.Wri teLine(s.CanDes erialize(xr));
suchkriterium = (suche.Suchkrit erium)s.Deseria lize(xr);
}
catch (Exception e)
{
Console.Out.Wri teLine(e.ToStri ng());
}

return suchkriterium;
}
set
{
suchkriterium = value; // setze die Objektreferenz

Type [] extraTypes = new Type[4];
extraTypes[0] = typeof(suche.No tIn);
extraTypes[1] = typeof(suche.Su chstring);
extraTypes[2] = typeof(suche.Un ion);
extraTypes[3] = typeof(suche.Ve rknuepfung);
XmlSerializer s = new XmlSerializer(s uchkriterium.Ge tType(),
extraTypes); // instanziiere XmlSerializier für Benutzung mit
XmlSuchkriteriu m

MemoryStream mem = new MemoryStream();
StreamWriter pobjStreamWrite r = new StreamWriter(me m, new
System.Text.UTF 8Encoding());

try
{
s.Serialize(pob jStreamWriter, suchkriterium); // just do
it.
}
catch (System.Xml.Xml Exception ex)
{
Console.Out.Wri teLine(ex.Messa ge);
}

mem.Position = 0;
xmlinhalt = new StreamReader(me m).ReadToEnd();

}
}

=============== =============== =============== =============== ====

Nov 11 '05 #2

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

Similar topics

0
1059
by: Jon Fairchild | last post by:
I am getting the following error when deserializing an XML with attribute overrides: "There is an error in XML document (2, 2) … <RulesConfig xmlns=''> was not expected" My XML looks like this: <RulesConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="D:\Dev\Source\Miner.Data.Configuration\RulesConfig.xsd"> <RulePackage Key="SwitchingSteps" Caption="Switching Steps">
12
2201
by: ABeck | last post by:
Hello List, I have ar more or less academical question. Can there arise runtime errors in a program, if the include of <string.h> has been forgotten? If all the arguments to the functions of <string.h> are correct, is it possible that an error occurs, and what an error might this be? Regards
4
6889
by: Matt Sawyer | last post by:
I am attempting to use an API (CxApiOem.dll) that has a large number of defines and complicated structs. It's just too much hassle to attempt to use DLLImport to make the desired API calls. Instead, I created a managed C++ DLL (OneBoxAPI.dll) that wraps the desired API calls in a manner which is easy to call from C#. This way I can use the header files that are part of the API for all the defines and structs. I am having a problem...
5
3154
by: Daniel Gackle | last post by:
I'm getting a strange ArgumentNullException after deserializing a SortedList. Haven't seen this discussed in the newsgroups, but it looks like a bug - unless I missed something obvious? I've distilled the problem into the following code. Can anybody reproduce/explain the problem? Thanks, Daniel
5
2806
by: Andrei Pociu | last post by:
I have a major doubt about outputting text in ASP .NET when using code behind. I know most of the output you gain from a code behind file (.aspx.cs) is outputted to the Webform (.aspx) using labels, datagrids, datalists... Also, I know you can output directly using Response.Write(). But this places the output at the beginning of the file. How can you output the text at a specific place in the HTML code? An example would be when...
7
4030
by: iclinux | last post by:
Environment: WinXP SP2 + Python 2.4.2, with SOAPpy-0.11.6.zip, fpconst-0.7.2.zip, and PyXML-0.8.4.win32-py2.4.exe installed. Problem: I'm reading DiveIntoPython these days. When running code of "Example 12.11. Calling A Web Service Through A WSDL Proxy", I got some errors as follow. Will you please give me some suggestion? IDLE 1.1.2's Output:
6
1551
by: kapro | last post by:
PHP behaves strange when capturing 'return' value, how to over come? when i echo the value inside the function, it works fine. if i return a value from the function, it return nothing... why? Assume, that the following is the table 'menu' and having the following fields(with values) menuid ====== 1
1
2235
by: kelly sinclair | last post by:
#include<stdio.h> int main() { char *name; float bal,stbal,deposits,withdrawals; int nw,nd,i; printf("Welcome to the Sinclair Banking System."); /* Introduction to program*/; printf("\n\nPlease enter your first name: "); /* User will be prompted to enter name*/;
0
8182
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8688
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8635
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8494
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7178
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6115
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2614
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1496
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.