473,654 Members | 3,082 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.write XML("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.Strea m and the
XPathDocument supports load from System.IO.Strea m but I can not seem to get
this to work.

Any suggestions?

Cheers
Keith
Nov 12 '05 #1
2 2956
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 "Synchroniz ing
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 "standardis ed" 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.Cur rent.Response.O utputStream
//To write to the Console pass in Console.OpenSta ndardOutput()
public Boolean TransformDatase t(System.IO.Str eam strmOut)
{
Boolean flgSuccess;
strmOutput = new StreamWriter(st rmOut,System.Te xt.Encoding.UTF 8,640);
flgSuccess = prvTransformDat aset();
strmOutput.Clos e();
return(flgSucce ss);
}

//String argument defines file to create
public Boolean TransformDatase t(string strOut)
{
Boolean flgSuccess;
strmOutput = new StreamWriter(st rOut);
flgSuccess = prvTransformDat aset();
strmOutput.Clos e();
return(flgSucce ss);
}

//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 TransformDatase t()
{
strmLocal = new MemoryStream();
strmLocal.Seek( 0,SeekOrigin.Be gin);
strmOutput = new StreamWriter(st rmLocal,System. Text.Encoding.U TF8,640);
try
{
if(prvTransform Dataset())
{
strmLocal.Posit ion = 0;
StreamReader strmRdOut = new
StreamReader(st rmLocal,System. Text.Encoding.U TF8);
return(strmRdOu t.ReadToEnd().T oString());
}
else
{
return("Failed! ");
}
}
finally
{
strmOutput.Clos e();
}
}

Stephen

"Keith Chadwick" <kc*******@leew ardsystems.com> wrote in message
news:ed******** ********@tk2msf tngp13.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.write XML("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.Strea m and the
XPathDocument supports load from System.IO.Strea m 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. Basically, all of the data is stored in an Access .mdb that is read into a dataset when the application is loaded. There are some minor changes to the schema between what is in the physical database to accomodate some things that Access just...
5
5637
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: XmlReader instance from another module (beyond my control)
2
3713
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 public inside the class)
2
4685
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 get this data into a dataset. XPathDocument doc = new XPathDocument(@"C:\inetpub\wwwroot\test\test.xml"); XPathNavigator nav = doc.CreateNavigator(); XPathNodeIterator iter = nav.Select("/test/translation/engword");
5
3059
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
1050
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 to supply a variable instead of the xml doc. This is the code I use: dim docNav As XPathDocument docNav = New XPathDocument("c:\adsp_dispatch.xml") I would like to use something like:
3
1814
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 based on the XML file I get from excel 2. Use a WriteXML to create a XML file in the format I need. Will this work? How do I get started on this? Are there any other alternate ways of doing this?
2
5653
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 --------------------------------------------------------------- //Create a new XslTransform object. XslTransform xslt = new XslTransform();
1
1768
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 dataset method to read the .xml files
0
8372
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8814
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8706
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8475
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7304
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5621
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4293
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2709
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 we have to send another system
1
1915
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.