Solved

How do I read xml into a dataset?

Posted on 2004-03-27
7
702 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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
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

How our DevOps Teams Maximize Uptime

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

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET 2008 Publish Error 2 34
Help with error in Query 2 31
Vb.net threads keep increasing 2 36
Where does legacy ASP.NET initialize language? 2 26
A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
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…

830 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