Solved

How do I read xml into a dataset?

Posted on 2004-03-27
7
701 Views
Last Modified: 2007-12-19
I am programming an application for a pocket pc using .net framework 1.1 and pocketpc 2003.

I need to get a dataset from the computer (server) into the pocketpc, but I am having trouble serializing the xml dataset from the server to the handheld.

The code on my server loads a dataset with a single table, and then writes the xml to a socketstream.

BinaryWriter writer = new BinaryWriter(strm);
string ret = ds.GetXml();
writer.Write(ret);

On the pocket pc side, I am using a binary reader to read the incoming xml stream.

StringReader xmlSR = new System.IO.StringReader(args.Xml);
xmlTextReader reader = new XmlTextReader(xmlSR);
ds.ReadXml(reader, XmlReadMode.Auto);

The result is, when I run this code, the args.Xml does contain XML data, but it is not getting read into the dataset. I pasted the xml from args.XML into xmlspy, but xml spy says it is not well formed xml. What is happening to the xml through the streaming? Or am I not loading the dataset correctly on the pocketpc side?

Thanks for your response.. I appreciate it very much. =]]
0
Comment
Question by:gregasm
  • 4
  • 3
7 Comments
 
LVL 8

Author Comment

by:gregasm
ID: 10696237
oh, btw, I noticed that after the xml received from the ds.GetXml function, it has "\r\n" characters in it.. I started by replacing all of those with empty spaces.. but the xml still seems to be malformed.
0
 
LVL 27

Expert Comment

by:Dabas
ID: 10696249
Hi gregasm:
Could you by chance post the xml file when it is malformed so that we can look at it for further clues?

Dabas
0
 
LVL 8

Author Comment

by:gregasm
ID: 10696290
well I can successfully load the string into an XMLDocument object... that must say something about its well-formedness... but somehow when I output it to a string in immediates window and then cut and paste that string into xmlspy, xml spy says it is malformed because there are spaces where there should be spaces... like this

<node1><nod
    e2></node2></node1>

When I fix all those errors by deleting the white space, it is a perfectly formed xml document.

I need to load this document into a dataset, starting with the xml in a string format... i am not able to do this yet.
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 27

Accepted Solution

by:
Dabas earned 500 total points
ID: 10696298
gregasm:
Just to clarify.
On the PC file, ret is properly formed, but args.xml is not?
If you are sending a string, should you not receive a string?

What exactly is args.Xml?

Dabas
0
 
LVL 8

Author Comment

by:gregasm
ID: 10696314
args is a class that derives from Eventargs, and it is sent to the eventhandler...

you know what, after I loaded the xml into an xmldoc object, and then used the xmldoc object's .innerxml property, lo and behold it loaded into the dataset via :

                  XmlDocument myDoc = new XmlDocument();
                  myDoc.LoadXml(args.Xml);
                  StringReader xmlSR = new System.IO.StringReader(myDoc.InnerXml);
                  XmlTextReader reader = new XmlTextReader(xmlSR);

                  ds.ReadXml(reader, XmlReadMode.Auto);

So, problem is solved.. I got the dataset onto the pocket pc. THANKS, Dabas! Talking to you helped get my mind going.
0
 
LVL 8

Author Comment

by:gregasm
ID: 10696334
although the points are already yours, I was wondering if you had any idea as to why I need to load the xmlDocument with the xml before the xml is formed properly to be loaded into the ds? It is something about the way the xmldoc massages the string as it loads it?

even though the problem is solved, this is something i am still wondering about...
0
 
LVL 27

Expert Comment

by:Dabas
ID: 10696352
gregasm:
I am glad I could help!
I was only trying to give pointers, that might actually help other experts solve your problem.
What I think happens is something like this:
You have xml that needs to be converted to plain string to be sent to the PocketPC.
A string object and an xml object are not exactly the same.
Hence the correct procedure is:
XML -> String -> SendToDevice -> ReceiveAtDevice (as String!) -> Convert back to XML
In your original code, you were reading the string, and assuming it was xml.
Probably due to the extra characters inserted such as CRLF it was not strictly speaking.

Hope this answers the q?

Dabas
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Need a starter for ETL protocol? 4 57
Show/Hide ASP.NET controls with JQuery best practices 3 48
C# bracket error 3 31
C# LINQ ForEach() question 6 28
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question