Solved

Create XML String from DataView?

Posted on 2007-04-02
4
743 Views
Last Modified: 2013-11-07
Using VWD 2005 and SQL 2005

What started out to be a quick and dirty tool has proved to be quite a distraction for me.  I have a need to retrieve records from a stored procedure, serialize them into XML and run a transformation on them with an XSL.

My first thought was to create a DAL.  So, using the dataset wizard I made a data object with one method to retrieve records with a parameter.

Next I dropped an XML object onto my web form.  I set the TransformationSource property to my XSL stylesheet and my thought was to set the DocumentContent property to an XML string.

Where was the XML content to come from?  I knew that the dataset has the GetXML method.  However, the DAL tableadapters return a datatable.  I can make a dataview from that, but that doesn't really help either.

I know that I can just code this by hand in a few minutes and get the XML from a dataset, but like I said - this really got me distracted - and I was wondering if there was a way to serialize the contents of the datatable or dataview that is returned.
0
Comment
Question by:manicsquirrel
[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
  • 2
4 Comments
 
LVL 5

Expert Comment

by:jef06
ID: 18841615
Try this :)

DataView data = new DataSet().Tables[0].DefaultView;
XmlSerializer serializer = new XmlSerializer(data.GetType());
                StringBuilder sb = new StringBuilder();
                TextWriter writer = new StringWriter(sb);

                serializer.Serialize(writer, data);
                StringReader reader = new StringReader(writer.ToString());

                DataSet dst = new DataSet();
                dst.ReadXml(reader);
                dv = new DataView(dst.Tables[0]);
0
 
LVL 28

Accepted Solution

by:
iboutchkine earned 500 total points
ID: 18842706
Serialize
\\\\
 Dim sw As New System.IO.StringWriter
 ds.WriteXml(sw)
 Dim mystring As String = sw.tostring
///
Deserialize
\\\
 Dim sr As New System.IO.StringReader(mystring)
 Dim ds2 As New DataSet
 ds2.ReadXml(sr)
///
0
 
LVL 6

Author Comment

by:manicsquirrel
ID: 18844222
I like using my brain a little, and while iboutchkine didn't write the routing for me, it was just enough to make a light bulb go off.  My resulting solution was (remember, I already have a dataview - dv)

        Dim sw As New System.IO.StringWriter
        dv.Table.WriteXml(sw)
        Dim str As String = sw.ToString

Now I have effectively retrieved serialized data from my dataview which is what I was wanting.  Thanks for both of your responses.
0
 
LVL 6

Author Comment

by:manicsquirrel
ID: 18844231
Did I type "routing"?  I meant "routine".
0

Featured Post

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

705 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