473,407 Members | 2,315 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,407 software developers and data experts.

Serialization to XmlTextReader results in null

I'm not sure how to do this, but in my n-tiered app, i need to pass
xmlreaders as parameters as opposed to strings and as opposed to
xmldocuments().

here's what I have, I can write fine to a file, but I don't want this IO
process--so I've taken that code out.

private XmlTextReader Serialize(object o)
{
/// <summary>
/// This method is used to serialize the message object
/// </summary>
/// <param name="obj">Request object</param>
MemoryStream ms = new MemoryStream();
XmlTextWriter xtw = new XmlTextWriter(ms,Encoding.UTF8);
XmlSerializer s = new XmlSerializer(o.GetType());

s.Serialize(xtw, o);

ms = (MemoryStream) xtw.BaseStream;
StreamReader sr = new StreamReader(ms);
XmlTextReader _xtr = new XmlTextReader( sr.ReadToEnd() );

return _xtr;
//return PackageSoap( _xtr );
}
May 10 '06 #1
1 1840
Perhaps this will help

public class GoogleGroupsQuestion
{
static void Main(string[] args)
{

Person P = new Person();
P.FirstName = "George";
P.LastName = "Best";

XmlTextReader xtr = Serialize (P);

while(xtr.Read())
{
Console.WriteLine(xtr.ReadOuterXml()) ;
}

Console.Read();

}

private static XmlTextReader Serialize(object o)
{
/// <summary>
/// This method is used to serialize the message object
/// </summary>
/// <param name="obj">Request object</param>
MemoryStream ms = new MemoryStream();

//XmlTextWriter xtw = new XmlTextWriter(ms,Encoding.UTF8);
XmlSerializer s = new XmlSerializer(o.GetType());

//s.Serialize (xtw, o);
s.Serialize (ms, o);

//ms = (MemoryStream) xtw.BaseStream ;
ms.Position = 0;

//StreamReader sr = new StreamReader(ms);
XmlTextReader _xtr = new XmlTextReader( ms );

return _xtr;
//return PackageSoap( _xtr );

}
} // end class

public class Person
{
private string fname;
private string lname;

public string FirstName
{
get { return fname; }
set { fname = value; }

}

public string LastName
{
get { return lname;}
set { lname = value; }

}
}
Dickster

May 11 '06 #2

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

Similar topics

5
by: Geoff Bennett | last post by:
While parsing an XML document, my TextReader instance skips nodes. For example, in this fragment: <Person Sex="Male" FirstHomeBuyer="No" YearsInCurrentProfession="14"> <RelatedEntityRef...
3
by: Ice | last post by:
All - I'm pretty comfortable with simple XML serialization of objects. However I observed something the other day and I wanted to know if I solved it the right way. Basically if I have a...
1
by: soupaman | last post by:
Im trying to output some filtered xml using the xmlTextReader I know the code and commenting needs cleaned up and eventually plan to add the values to a dataset. currently what this is doing is...
0
by: HakonB | last post by:
Hi all I get an exception when trying to deserialize a simple configuration file using XML Serialization. The very long stacktrace can be seen at the bottom of this message. I've see other...
2
by: Q | last post by:
I am feeding XmlTextReader a URL that returns the XML that then gets parsed. The URL forms a query that affects how much data is returned in XML but not the format of the data. The problem is...
0
by: psy000 | last post by:
Hi, I have a C# web service client that talks to a JAVA application sever. I use AXIS to generate the WSDL file, use wsdl.exe to generate proxy stub c# code. When I try to use c# client connect...
5
by: Arjen | last post by:
Hello, Can somebody help me a little bit? I can't get it to work. Please see my code below... I have placed some comments like "// And whats next?". I'm sure that I have to code something...
5
by: Tamir Khason | last post by:
I have an object (eg MyObject with namespace eg MyNamespace) public class MyObject While I serialize it the XML created is <MyObject xmlns:xsd="http://www.w3.org/2001/XMLSchema"...
1
by: John S | last post by:
I understand what serialization is (saving values to a file). Can someone give me a quick, easy-to-understand example of using serialization? Please do not send me the microsoft example. I've...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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...
0
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...
0
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,...

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.