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.Suchkriterium
{
public Suchstring() { this.sqlString = ""; }
public Suchstring(string sqlString)
{
this.sqlString = sqlString;
}
public override string SqlString
{
get
{
return sqlString;
}
set
{
sqlString = value;
}
}
public override string toXml() {
return "<Suchstring xmlns:xsd=\"http:www.w3.org/2001/XMLScheme\" \n
xmlns:xsi=\"http:www.w3.org/2001/XMLScheme-instance\">\n<sqlString>" +
this.sqlString + "</sqlString>";
}
}
public abstract class Verknuepfung :
bee2bee.edb.dal.suche.Suchkriterium
{
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=\"http:www.w3.org/2001/XMLScheme\" \n
xmlns:xsi=\"http:www.w3.org/2001/XMLScheme-instance\">\n<LinkerKnoten>";
s += this.linkerKnoten.toXml() +
"</LinkerKnoten>\n<RechterKnoten>";
s += this.rechterKnoten.toXml() + "</RechterKnoten></";
s += this.GetType().Name + ">";
return s;
}
}
public class NotIn : bee2bee.edb.dal.suche.Verknuepfung
{
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.SqlString + ") tbl_" +
System.DateTime.Now.Ticks + " WHERE id NOT IN (" +
rechterKnoten.SqlString + "))";
}
else
{
throw new bee2bee.edb.exceptions.dbSuchkriteriumException("b ee2bee.edb.dal.suche.NotIn:
Mindestens einer der beiden Knoten ist null.");
}
}
set
{
throw new bee2bee.edb.exceptions.dbSuchkriteriumException("D er
SqlString eines NotIn-Operators wird berechnet. Er kann nicht gesetzt
werden.");
}
}
}
public class Union : bee2bee.edb.dal.suche.Verknuepfung
{
public Union()
{
linkerKnoten = null;
rechterKnoten = null;
}
public override string SqlString
{
get
{
if (linkerKnoten == null && rechterKnoten == null)
{
throw new bee2bee.edb.exceptions.dbSuchkriteriumException("b ee2bee.edb.dal.suche.Union:
Beide Kinder des Union-Operators sind null.");
}
else if (linkerKnoten != null && rechterKnoten != null)
{
return "(SELECT id FROM ((" + linkerKnoten.SqlString + ") UNION
(" + rechterKnoten.SqlString + ")) tbl_" + System.DateTime.Now.Ticks +
")";
}
else if (linkerKnoten == null)
{
return rechterKnoten.SqlString;
}
else
{
return linkerKnoten.SqlString;
}
}
set
{
throw new bee2bee.edb.exceptions.dbSuchkriteriumException("D er
SqlString eines Union-Operators wird berechnet. Er kann nicht gesetzt
werden.");
}
}
}
Property for (de-)serializing:
================================================== ==============
public suche.Suchkriterium Suchkriterium
{
get
{
// deserialisiere xmlinhalt -> suchkriterium
// benutze dabei die Wrapper-Klasse XmlSuchkriterium, da
Suchkriterium nicht direkt serialisiert werden kann
Type [] extraTypes = new Type[4];
extraTypes[0] = typeof(suche.NotIn);
extraTypes[1] = typeof(suche.Suchstring);
extraTypes[2] = typeof(suche.Union);
extraTypes[3] = typeof(suche.Verknuepfung);
XmlSerializer s = new XmlSerializer(suchkriterium.GetType(),
extraTypes);
StringReader sr = new StringReader(xmlinhalt);
XmlTextReader xr = new XmlTextReader(sr);
Console.Out.WriteLine(xmlinhalt);
try
{
Console.Out.WriteLine(s.CanDeserialize(xr));
suchkriterium = (suche.Suchkriterium)s.Deserialize(xr);
}
catch (Exception e)
{
Console.Out.WriteLine(e.ToString());
}
return suchkriterium;
}
set
{
suchkriterium = value; // setze die Objektreferenz
Type [] extraTypes = new Type[4];
extraTypes[0] = typeof(suche.NotIn);
extraTypes[1] = typeof(suche.Suchstring);
extraTypes[2] = typeof(suche.Union);
extraTypes[3] = typeof(suche.Verknuepfung);
XmlSerializer s = new XmlSerializer(suchkriterium.GetType(),
extraTypes); // instanziiere XmlSerializier für Benutzung mit
XmlSuchkriterium
MemoryStream mem = new MemoryStream();
StreamWriter pobjStreamWriter = new StreamWriter(mem, new
System.Text.UTF8Encoding());
try
{
s.Serialize(pobjStreamWriter, suchkriterium); // just do
it.
}
catch (System.Xml.XmlException ex)
{
Console.Out.WriteLine(ex.Message);
}
mem.Position = 0;
xmlinhalt = new StreamReader(mem).ReadToEnd();
}
}
================================================== ============== 1 1825
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.google.c om... 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.Suchkriterium {
public Suchstring() { this.sqlString = ""; }
public Suchstring(string sqlString) { this.sqlString = sqlString; }
public override string SqlString { get { return sqlString; } set { sqlString = value; } }
public override string toXml() { return "<Suchstring xmlns:xsd=\"http:www.w3.org/2001/XMLScheme\" \n xmlns:xsi=\"http:www.w3.org/2001/XMLScheme-instance\">\n<sqlString>" + this.sqlString + "</sqlString>"; } }
public abstract class Verknuepfung : bee2bee.edb.dal.suche.Suchkriterium { 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=\"http:www.w3.org/2001/XMLScheme\" \n xmlns:xsi=\"http:www.w3.org/2001/XMLScheme-instance\">\n<LinkerKnoten>"; s += this.linkerKnoten.toXml() + "</LinkerKnoten>\n<RechterKnoten>"; s += this.rechterKnoten.toXml() + "</RechterKnoten></"; s += this.GetType().Name + ">"; return s; } }
public class NotIn : bee2bee.edb.dal.suche.Verknuepfung {
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.SqlString + ") tbl_" + System.DateTime.Now.Ticks + " WHERE id NOT IN (" + rechterKnoten.SqlString + "))"; } else { throw new
bee2bee.edb.exceptions.dbSuchkriteriumException("b ee2bee.edb.dal.suche.NotIn
: Mindestens einer der beiden Knoten ist null."); } } set { throw new bee2bee.edb.exceptions.dbSuchkriteriumException("D er SqlString eines NotIn-Operators wird berechnet. Er kann nicht gesetzt werden."); } } }
public class Union : bee2bee.edb.dal.suche.Verknuepfung { public Union() { linkerKnoten = null; rechterKnoten = null; }
public override string SqlString {
get { if (linkerKnoten == null && rechterKnoten == null) { throw new
bee2bee.edb.exceptions.dbSuchkriteriumException("b ee2bee.edb.dal.suche.Union
: Beide Kinder des Union-Operators sind null."); } else if (linkerKnoten != null && rechterKnoten != null) {
return "(SELECT id FROM ((" + linkerKnoten.SqlString + ") UNION (" + rechterKnoten.SqlString + ")) tbl_" + System.DateTime.Now.Ticks + ")"; } else if (linkerKnoten == null) { return rechterKnoten.SqlString; } else { return linkerKnoten.SqlString; } } set { throw new bee2bee.edb.exceptions.dbSuchkriteriumException("D er SqlString eines Union-Operators wird berechnet. Er kann nicht gesetzt werden."); } } }
Property for (de-)serializing:
================================================== ==============
public suche.Suchkriterium Suchkriterium { get { // deserialisiere xmlinhalt -> suchkriterium // benutze dabei die Wrapper-Klasse XmlSuchkriterium, da Suchkriterium nicht direkt serialisiert werden kann Type [] extraTypes = new Type[4]; extraTypes[0] = typeof(suche.NotIn); extraTypes[1] = typeof(suche.Suchstring); extraTypes[2] = typeof(suche.Union); extraTypes[3] = typeof(suche.Verknuepfung);
XmlSerializer s = new XmlSerializer(suchkriterium.GetType(), extraTypes); StringReader sr = new StringReader(xmlinhalt); XmlTextReader xr = new XmlTextReader(sr); Console.Out.WriteLine(xmlinhalt); try { Console.Out.WriteLine(s.CanDeserialize(xr)); suchkriterium = (suche.Suchkriterium)s.Deserialize(xr); } catch (Exception e) { Console.Out.WriteLine(e.ToString()); }
return suchkriterium; } set { suchkriterium = value; // setze die Objektreferenz
Type [] extraTypes = new Type[4]; extraTypes[0] = typeof(suche.NotIn); extraTypes[1] = typeof(suche.Suchstring); extraTypes[2] = typeof(suche.Union); extraTypes[3] = typeof(suche.Verknuepfung); XmlSerializer s = new XmlSerializer(suchkriterium.GetType(), extraTypes); // instanziiere XmlSerializier für Benutzung mit XmlSuchkriterium
MemoryStream mem = new MemoryStream(); StreamWriter pobjStreamWriter = new StreamWriter(mem, new System.Text.UTF8Encoding());
try { s.Serialize(pobjStreamWriter, suchkriterium); // just do it. } catch (System.Xml.XmlException ex) { Console.Out.WriteLine(ex.Message); }
mem.Position = 0; xmlinhalt = new StreamReader(mem).ReadToEnd();
} }
================================================== ============== This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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:...
|
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...
|
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. ...
|
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...
|
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...
|
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...
|
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?
...
|
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*/;...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
| | |