473,657 Members | 2,415 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Serialized class from XSDObjectGen results in invalid char at position 1,1

Ste
I generated a class from an XSD using XSDObjectGen, when i try to create an xml serialized string from it i get an invalid char in position 1,1

The code i use to serialise the object is pasted below.. lifted from http://www.dotnetjohn.com/articles.aspx?articleid=173

The char at position 1 is displayed as a "?" so some encoding is taking place.. it has a hex value is 0xFeFF

Can anyone spot an obvious mistake??


private String UTF8ByteArrayTo String(Byte[] characters)
{
UTF8Encoding encoding = new UTF8Encoding();
String constructedStri ng = encoding.GetStr ing(characters) ;
return (constructedStr ing);
}
XmlInput inp = new XmlInput();
inp.AddSomethin g();

MemoryStream memoryStream = new MemoryStream();
memoryStream.Po sition = 0;
XmlSerializer xs = new XmlSerializer(t ypeof(XmlInput) );
XmlTextWriter xmlTextWriter = new XmlTextWriter(m emoryStream, Encoding.UTF8);
xs.Serialize(xm lTextWriter, inp);
memoryStream = (MemoryStream)x mlTextWriter.Ba seStream;
XmlizedString = UTF8ByteArrayTo String(memorySt ream.ToArray()) ;
System.Console. WriteLine(Xmliz edString);
... output xml all looks ok ...apart from leading char
"?<?xml version=\"1.0\" encoding=\"utf-8\"?><XmlInpu t xmlns:xsd=\"htt p://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"htt p://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:My. XmlInput\"><Ser vice>XXX</Service</XmlInput>"
Nov 17 '05 #1
2 3040
try the following and tell us what you get:

XmlInput inp = new XmlInput();
inp.AddSomethin g();

System.Text.Str ingBuilder sbSer = new System.Text.Str ingBuilder();
using(System.IO .StringWriter sw = new System.IO.Strin gWriter(sbSer))
{
XmlSerializer ser = new XmlSerializer(t ypeof(XmlInput) );
ser.Serialize(s w, inp);
}
Console.WriteLi ne(sbSer.ToStri ng()));

HTH

Ollie Riches
"Ste" <no*****@nospam .com> wrote in message
news:hY******** ************@pi pex.net...
I generated a class from an XSD using XSDObjectGen, when i try to create an
xml serialized string from it i get an invalid char in position 1,1

The code i use to serialise the object is pasted below.. lifted from
http://www.dotnetjohn.com/articles.aspx?articleid=173

The char at position 1 is displayed as a "?" so some encoding is taking
place.. it has a hex value is 0xFeFF

Can anyone spot an obvious mistake??


private String UTF8ByteArrayTo String(Byte[] characters)
{
UTF8Encoding encoding = new UTF8Encoding();
String constructedStri ng = encoding.GetStr ing(characters) ;
return (constructedStr ing);
}
XmlInput inp = new XmlInput();
inp.AddSomethin g();

MemoryStream memoryStream = new MemoryStream();
memoryStream.Po sition = 0;
XmlSerializer xs = new XmlSerializer(t ypeof(XmlInput) );
XmlTextWriter xmlTextWriter = new XmlTextWriter(m emoryStream,
Encoding.UTF8);
xs.Serialize(xm lTextWriter, inp);
memoryStream = (MemoryStream)x mlTextWriter.Ba seStream;
XmlizedString = UTF8ByteArrayTo String(memorySt ream.ToArray()) ;
System.Console. WriteLine(Xmliz edString);
... output xml all looks ok ...apart from leading char
"??<?xml version=\"1.0\" encoding=\"utf-8\"?><XmlInpu t
xmlns:xsd=\"htt p://www.w3.org/2001/XMLSchema\"
xmlns:xsi=\"htt p://www.w3.org/2001/XMLSchema-instance\"
xmlns=\"urn:My. XmlInput\"><Ser vice>XXX</Service</XmlInput>"
Nov 17 '05 #2
Ste
That worked a treat. thanks....

I actually fixed the original version

by replacing

XmlTextWriter xmlTextWriter = new XmlTextWriter(m emoryStream,
Encoding.UTF8);

with

XmlTextWriter xmlTextWriter = new XmlTextWriter(m emoryStream, new
UTF8Encoding()) ;

Which is the most efficient.. if minimum lines or code where the issue -
your version would win hands down !


"Ollie Riches" <ol**********@p honeanalyser.ne t> wrote in message
news:OZ******** ******@TK2MSFTN GP09.phx.gbl...
try the following and tell us what you get:

XmlInput inp = new XmlInput();
inp.AddSomethin g();

System.Text.Str ingBuilder sbSer = new System.Text.Str ingBuilder();
using(System.IO .StringWriter sw = new System.IO.Strin gWriter(sbSer))
{
XmlSerializer ser = new XmlSerializer(t ypeof(XmlInput) );
ser.Serialize(s w, inp);
}
Console.WriteLi ne(sbSer.ToStri ng()));

HTH

Ollie Riches
"Ste" <no*****@nospam .com> wrote in message
news:hY******** ************@pi pex.net...
I generated a class from an XSD using XSDObjectGen, when i try to create
an xml serialized string from it i get an invalid char in position 1,1

The code i use to serialise the object is pasted below.. lifted from
http://www.dotnetjohn.com/articles.aspx?articleid=173

The char at position 1 is displayed as a "?" so some encoding is taking
place.. it has a hex value is 0xFeFF

Can anyone spot an obvious mistake??


private String UTF8ByteArrayTo String(Byte[] characters)
{
UTF8Encoding encoding = new UTF8Encoding();
String constructedStri ng = encoding.GetStr ing(characters) ;
return (constructedStr ing);
}
XmlInput inp = new XmlInput();
inp.AddSomethin g();

MemoryStream memoryStream = new MemoryStream();
memoryStream.Po sition = 0;
XmlSerializer xs = new XmlSerializer(t ypeof(XmlInput) );
XmlTextWriter xmlTextWriter = new XmlTextWriter(m emoryStream,
Encoding.UTF8);
xs.Serialize(xm lTextWriter, inp);
memoryStream = (MemoryStream)x mlTextWriter.Ba seStream;
XmlizedString = UTF8ByteArrayTo String(memorySt ream.ToArray()) ;
System.Console. WriteLine(Xmliz edString);
.. output xml all looks ok ...apart from leading char
"??<?xml version=\"1.0\" encoding=\"utf-8\"?><XmlInpu t
xmlns:xsd=\"htt p://www.w3.org/2001/XMLSchema\"
xmlns:xsi=\"htt p://www.w3.org/2001/XMLSchema-instance\"
xmlns=\"urn:My. XmlInput\"><Ser vice>XXX</Service</XmlInput>"

Nov 17 '05 #3

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

Similar topics

9
8693
by: David Carter-Hitchin | last post by:
Hi, I'm not very experienced with c++ so I'm sure this is something obvious that is easily solved, but for the life of me I can't seem to figure it out. I'd be very grateful for some knowledgeable insight into this. My class Position has a string (private, public - doesn't seem to matter which), which I construct in a member function and wish to return calls from main(). However, although
0
1475
by: Andrew Burgher | last post by:
Feeding the following .xsd into the XsdObjectGen (v1.4.2.0) tool produces an invalid attribute: with DataType="System.String". Has anybody seen this behaviour before? Is this a bug in XsdObjectGen? or a problem with the input schema? I'm trying to avoid hacking the generated code... In: <?xml version = "1.0" encoding = "UTF-8"?> <xsd:schema elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
0
2380
by: TT (Tom Tempelaere) | last post by:
Hi there, I'm using the XSDObjectGen tool to generate a class described as an XSD. <url http://www.microsoft.com/downloads/details.aspx?FamilyID=89e6b1e5-f66c-4a4d-933b-46222bb01eb0&DisplayLang=en </url> The generated class compiles correctly. But I do not know how I should _use_ the generated files, and I can't seem to find a good example that does.
0
2682
by: Tommy Christian | last post by:
Hi! Anyone who knows about saving serialized data to database, coz I have a problem with that. If I just serialize my session data and then deserialize it, it works. But when I save it between those actions into Oracle database into long row field, it doesn´t. Below is some code.
0
874
by: Jack Fox | last post by:
Some dotnet functionality only works in conjunction with streams. A couple of times I have only wanted to place the results in a string. This is one of those cases. Is there any way I can do this in fewer lines of code? It was suggested to me to pass state from one page to the next by serializing an object. I was further told that it is a one line process on each end to serialize a simple object to XML and transfer it to another page,...
0
962
by: wc chan | last post by:
I generated an object class by using xsdobjectgen from MS. The object class was OK in our programs. However, when we want to pass the object to a webservice, we got problem. We found that the proxy class generated by 'Add Web Reference' could not be referenced in client program. We got 'object reference not found' error whenever we referred to any element of the object. We could not create the object and passed to any webservices we coded....
0
2541
by: Don Leckie | last post by:
Hi, I hope someone can really help me. This problem has me stumped. I have class "A" that does not implement Serializable, but class "A" subclasses Serializable class "B". Therefore, when reading class "A" it should be read as a serialized class. Class "A" has one data member "private char m_operator". When I compile with JDK 1.3.1_17, the data file is read correctly.
3
2305
by: Stephen Torri | last post by:
Below is a class that is suppose to represent a segment of memory or a contents of a binary image (e.g. ELF executable). I have started to read Modern C++ Design and thought the best way to ensure I was understanding the chapter on policy classes was to attempt to apply them to my project. I understand the general concept of policies but I lack the knowledge and wisdom of how to identify them in an existing project. So I figured to get an...
2
16260
by: audiokarate | last post by:
I have like atleast 15 errors that say class, interface, or enum expected and I have no idea what that means. Can someone tell me what it is and how I might be able to fix it? Thank you. - Manny *Program Purpose: This program processes the results for the 2008 Democratic and/or Republican presidential primary elections.
0
8413
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8324
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
8842
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...
1
8513
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8617
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
7352
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
6176
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
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2742
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

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.