?
Solved

How do I read xml into a dataset?

Posted on 2004-03-27
7
Medium Priority
?
706 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
LVL 27

Accepted Solution

by:
Dabas earned 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

771 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