Solved

How do I read xml into a dataset?

Posted on 2004-03-27
7
698 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now