Solved

How do I read xml into a dataset?

Posted on 2004-03-27
7
703 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

737 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