Placing dataset into XPathDocument

Discussion in 'ASP .Net' started by Keith Chadwick, Nov 23, 2003.

  1. 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
    Keith Chadwick, Nov 23, 2003
    #1
    1. Advertising

  2. Keith Chadwick

    Guest Guest

    Hello Keith,

    I have a suggestion for you which worked really well for
    me.

    1. Create a string of your DataSet by using GetXml()
    string something = mydataset.GetXml();
    2. Create a new XmlDocument object and instantiate it
    with DataSet string "something"
    XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.LoadXml(something);
    3. Read the XmlDocument into the XPathDocument
    XPathDocument xpath = new XPathDocument(new
    XmlNodeReader(xmlDoc.DocumentElement());

    Hope this helps!
    Vivek

    >-----Original Message-----
    >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
    >
    >
    >.
    >
    Guest, Nov 24, 2003
    #2
    1. Advertising

  3. Thanks Vivek, knew that had to be a way.

    Cheers
    Keith

    <> wrote in message
    news:05b901c3b224$1909b820$...
    > Hello Keith,
    >
    > I have a suggestion for you which worked really well for
    > me.
    >
    > 1. Create a string of your DataSet by using GetXml()
    > string something = mydataset.GetXml();
    > 2. Create a new XmlDocument object and instantiate it
    > with DataSet string "something"
    > XmlDocument xmlDoc = new XmlDocument();
    > xmlDoc.LoadXml(something);
    > 3. Read the XmlDocument into the XPathDocument
    > XPathDocument xpath = new XPathDocument(new
    > XmlNodeReader(xmlDoc.DocumentElement());
    >
    > Hope this helps!
    > Vivek
    >
    > >-----Original Message-----
    > >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
    > >
    > >
    > >.
    > >
    Keith Chadwick, Nov 24, 2003
    #3
  4. 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/d...onSynchronizingDataSetWithXmlDataDocument.asp

    --
    Oleg Tkachenko
    XML Insider
    http://www.tkachenko.com/blog
    Oleg Tkachenko, Nov 24, 2003
    #4
  5. Keith Chadwick

    Stephen Cook Guest

    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,640);
    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" <> wrote in message
    news:ed0Ad%...
    > 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
    >
    >
    Stephen Cook, Nov 24, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. D
    Replies:
    2
    Views:
    590
  2. srikar

    XPathDocument

    srikar, Oct 25, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    420
    Guest
    Oct 26, 2003
  3. =?Utf-8?B?U2VhbiBIb2ZmbWFu?=

    Very Slow XSLTransform with XPathDocument

    =?Utf-8?B?U2VhbiBIb2ZmbWFu?=, Nov 18, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    501
    =?Utf-8?B?U2VhbiBIb2ZmbWFu?=
    Nov 18, 2004
  4. ThatsIT.net.au

    RSS, XPathDocument and ISA proxy server

    ThatsIT.net.au, Mar 24, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    313
    ThatsIT.net.au
    Mar 24, 2007
  5. .NETed
    Replies:
    3
    Views:
    1,020
    bruce barker
    Nov 6, 2009
Loading...

Share This Page