473,503 Members | 1,655 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Placing dataset into XPathDocument

I have a merged dataset that contains xml read from SQL Server. I need to
place the data into an XPathDocument.

I can do the following:

mydataset.writeXML("mydata.xml")
dim xpdoc as new XPathDocument("mydata.xml")

Problem is it seem rather redundent to write data currently in memory to
disk in order to be read on the next line. According to the documentation
the writeXML method supports writing to System.IO.Stream and the
XPathDocument supports load from System.IO.Stream but I can not seem to get
this to work.

Any suggestions?

Cheers
Keith
Nov 12 '05 #1
2 2946
Keith Chadwick wrote:
I have a merged dataset that contains xml read from SQL Server. I need to
place the data into an XPathDocument.


Make sure you really need it. In fact, to be able to query DataSet using
XPath or to transform it using XSLT all you need is XmlDataDocument
wrapper, synchronized with the DataSet. Take a look into "Synchronizing
a DataSet with an XmlDataDocument" article at
http://msdn.microsoft.com/library/de...taDocument.asp

--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Nov 12 '05 #2
Keith,

Using streams can get a bit interesting
I have a habit of tying myself in knots by creating one level too many of
writers and readers before I factor out all the rubbish again
I've "standardised" on the following overloads to methods that return
streams (callers for my earlier Transform dataset example)
Note should probably give thought to using exceptions to flag failure
//Accept a stream to handle web response
//Can be called from ASP.Net using HttpContext.Current.Response.OutputStream
//To write to the Console pass in Console.OpenStandardOutput()
public Boolean TransformDataset(System.IO.Stream strmOut)
{
Boolean flgSuccess;
strmOutput = new StreamWriter(strmOut,System.Text.Encoding.UTF8,640 );
flgSuccess = prvTransformDataset();
strmOutput.Close();
return(flgSuccess);
}

//String argument defines file to create
public Boolean TransformDataset(string strOut)
{
Boolean flgSuccess;
strmOutput = new StreamWriter(strOut);
flgSuccess = prvTransformDataset();
strmOutput.Close();
return(flgSuccess);
}

//Overload that returns a string
//Uses an in memory stream as a buffer
//Not sure that this is the best way to achieve this
public string TransformDataset()
{
strmLocal = new MemoryStream();
strmLocal.Seek(0,SeekOrigin.Begin);
strmOutput = new StreamWriter(strmLocal,System.Text.Encoding.UTF8,6 40);
try
{
if(prvTransformDataset())
{
strmLocal.Position = 0;
StreamReader strmRdOut = new
StreamReader(strmLocal,System.Text.Encoding.UTF8);
return(strmRdOut.ReadToEnd().ToString());
}
else
{
return("Failed!");
}
}
finally
{
strmOutput.Close();
}
}

Stephen

"Keith Chadwick" <kc*******@leewardsystems.com> wrote in message
news:ed****************@tk2msftngp13.phx.gbl...
I have a merged dataset that contains xml read from SQL Server. I need to
place the data into an XPathDocument.

I can do the following:

mydataset.writeXML("mydata.xml")
dim xpdoc as new XPathDocument("mydata.xml")

Problem is it seem rather redundent to write data currently in memory to
disk in order to be read on the next line. According to the documentation
the writeXML method supports writing to System.IO.Stream and the
XPathDocument supports load from System.IO.Stream but I can not seem to get this to work.

Any suggestions?

Cheers
Keith

Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
363
by: Wil | last post by:
I'm very new to developing in .NET and even newer to XML. The past few days have been pretty frustrating for me because I'm trying to perform a transform on data in a dataset and it's not working....
5
5622
by: xmlguy | last post by:
I believe this should be pretty elementary, but for some reason I cannot seem to think of how to write the an XML file from an incoming XML file. Basically this is what I do: Input: ...
2
3702
by: xmlguy | last post by:
Cant seem to solve this problem I need to be able to re-use XmlReader and XPathDocument for an XSLT Transform. Basically I have defined following interfaces: Class Render (Common and...
2
4677
by: Mike P | last post by:
I'm currently reading data from an XML file using XPathNavigator and XPathNodeIterator to select the subset of data that I want. I've never using the XPath objects before so I'm not sure how to...
5
3048
by: George Durzi | last post by:
Folks, I'd like to write out a DataSet's Xml into an XmlReader? How do I do that? Thanks!
0
1038
by: Joe Pannone | last post by:
I need a way to allow a variable to equal an xml document. When using xpathdocument the parameter is asking for a filename. Since I plan on doing a lot of search in the xml document I would like...
3
1802
by: sandeshmeda | last post by:
I have a XML file that is basically a Excel file saved as XML. I need to be able to change the XML into a different format. I was thinking one approach would be to: 1. Populate the dataset...
2
5642
by: kamil.nowicki | last post by:
Hi there, I want to create flat txt file from my data stored in my dataset. I do xslt transformation and i've got sth like that: (where ds - is my dataset, output.txt - is my result ...
1
1765
by: raghudr | last post by:
Hi all, I am parsing an .xml file.My main intention is to retrieve the field value:- "Name Value" which is "rag" and store it in a List. Fot that i wrote code like this: //i am using...
0
7083
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7278
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6988
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7456
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5011
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3153
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1510
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
379
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.