Query data (SELECT * FROM table) from XML File

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?RnJhbmsgVXJheQ==?=

    Query data (SELECT * FROM table) from XML File

    Hi all

    On SQL Server tables I use SqlDataReader to query data
    like "SELECT * FROM table".

    Is there something similar for XML Files ?
    I want to use SQL Syntax like "SELECT * FROM table" on
    a XML file. After query I want to get something like SqlDataReader
    based on Query to loop.
    I do not want to use a DataSet. It should be more like streaming
    and not loading the whole set into Memory.

    Any ideas ?
    Thanks for any comments.

    Best regards
    Frank
  • Jon Skeet [C# MVP]

    #2
    Re: Query data (SELECT * FROM table) from XML File

    On May 15, 11:00 am, Frank Uray <FrankU...@disc ussions.microso ft.com>
    wrote:
    On SQL Server tables I use SqlDataReader to query data
    like "SELECT * FROM table".
    >
    Is there something similar for XML Files ?
    I want to use SQL Syntax like "SELECT * FROM table" on
    a XML file. After query I want to get something like SqlDataReader
    based on Query to loop.
    I do not want to use a DataSet. It should be more like streaming
    and not loading the whole set into Memory.
    If you use LINQ to XML you can use SQL-like syntax (though not SQL
    itself) and get compile-time checking too.

    I don't know if LINQ to XML supports streaming. This post:

    suggests that it doesn't, for input. You may be able to search for
    some workarounds though.

    Of course, using LINQ to XML to start with assumes you're able to
    use .NET 3.5 - is that likely to be a problem for you?

    Jon

    Comment

    • Jon Skeet [C# MVP]

      #3
      Re: Query data (SELECT * FROM table) from XML File

      On May 15, 11:11 am, "Jon Skeet [C# MVP] <sk...@pobox.co m>"
      <sk...@pobox.co mwrote:

      <snip>
      I don't know if LINQ to XML supports streaming. This post: [...]
      suggests that it doesn't, for input. You may be able to search for
      some workarounds though.
      One example:



      Jon

      Comment

      • Misbah Arefin

        #4
        Re: Query data (SELECT * FROM table) from XML File

        You could use LINQ or XPath & XmlReader but I don’t think there is any SQL
        over XML provider


        --
        Misbah Arefin






        "Frank Uray" <FrankUray@disc ussions.microso ft.comwrote in message
        news:E30E2F83-AB4B-40F6-A6AF-24E33AB0FD4E@mi crosoft.com...
        Hi all
        >
        On SQL Server tables I use SqlDataReader to query data
        like "SELECT * FROM table".
        >
        Is there something similar for XML Files ?
        I want to use SQL Syntax like "SELECT * FROM table" on
        a XML file. After query I want to get something like SqlDataReader
        based on Query to loop.
        I do not want to use a DataSet. It should be more like streaming
        and not loading the whole set into Memory.
        >
        Any ideas ?
        Thanks for any comments.
        >
        Best regards
        Frank
        >

        Comment

        • Cor Ligthert [MVP]

          #5
          Re: Query data (SELECT * FROM table) from XML File

          Frank,

          In C# there is not a Linq to XML solution, however what is wrong with the
          dataset.

          You get mostly an XML file in a dataset with

          ds.readXML(path ).

          The dataset is a very optimized OO collection so I am very interested what
          will be the problem?

          Every other method will probably consume more memory and at least more
          resources.

          Cor

          "Frank Uray" <FrankUray@disc ussions.microso ft.comschreef in bericht
          news:E30E2F83-AB4B-40F6-A6AF-24E33AB0FD4E@mi crosoft.com...
          Hi all
          >
          On SQL Server tables I use SqlDataReader to query data
          like "SELECT * FROM table".
          >
          Is there something similar for XML Files ?
          I want to use SQL Syntax like "SELECT * FROM table" on
          a XML file. After query I want to get something like SqlDataReader
          based on Query to loop.
          I do not want to use a DataSet. It should be more like streaming
          and not loading the whole set into Memory.
          >
          Any ideas ?
          Thanks for any comments.
          >
          Best regards
          Frank

          Comment

          • Marc Gravell

            #6
            Re: Query data (SELECT * FROM table) from XML File

            You get mostly an XML file in a dataset with
            >
            ds.readXML(path ).
            >
            The dataset is a very optimized OO collection so I am very interested what
            will be the problem?
            Well, it doesn't work so well with huge volumes...
            Every other method will probably consume more memory and at least more
            resources.
            Well, except XmlReader... I do have a streaming (yield iterator)
            XmlReader in my toolkit, but it is quite lengthy and has some
            limitations - for example it assumes that all the "fields" are direct
            descendents (either elements or attributes) of the element you are
            reading, and it takes no account of hierarchy (it just uses
            MoveToFollowing to get the next candidate record). Maybe I'll write it
            up some time and put it somewhere more public...

            Marc

            Comment

            • =?Utf-8?B?RnJhbmsgVXJheQ==?=

              #7
              Re: Query data (SELECT * FROM table) from XML File

              Hi Cor

              Thanks for your answer.

              I have a application that has online connection
              to SQL Server (SqlDataReader ...).
              In this application, as a SQL Engineer, I use SQL Syntax.

              First is I want SQL Server to select subsets of data,
              I dont want to load it all into local Application Memory.
              But the real problem is, I want to change application to
              be able to run in a offline modus using XML files.

              If I would be able to somehow create SqlDataReader from
              DataSet and/or XML File, I dont have to change a lot within
              the application. Data Syncronizing would not be a big deal.

              So, I guess there is no solution to do this and I
              have to change the whole application to use DataSet.
              Than I am able to use both, online and offline.

              Thanks anyway
              Frank


              "Cor Ligthert [MVP]" wrote:
              Frank,
              >
              In C# there is not a Linq to XML solution, however what is wrong with the
              dataset.
              >
              You get mostly an XML file in a dataset with
              >
              ds.readXML(path ).
              >
              The dataset is a very optimized OO collection so I am very interested what
              will be the problem?
              >
              Every other method will probably consume more memory and at least more
              resources.
              >
              Cor
              >
              "Frank Uray" <FrankUray@disc ussions.microso ft.comschreef in bericht
              news:E30E2F83-AB4B-40F6-A6AF-24E33AB0FD4E@mi crosoft.com...
              Hi all

              On SQL Server tables I use SqlDataReader to query data
              like "SELECT * FROM table".

              Is there something similar for XML Files ?
              I want to use SQL Syntax like "SELECT * FROM table" on
              a XML file. After query I want to get something like SqlDataReader
              based on Query to loop.
              I do not want to use a DataSet. It should be more like streaming
              and not loading the whole set into Memory.

              Any ideas ?
              Thanks for any comments.

              Best regards
              Frank
              >
              >
              >

              Comment

              • Marc Gravell

                #8
                Re: Query data (SELECT * FROM table) from XML File

                For reference, you might be interested in sync framework:

                (when it is released, at least...)

                Marc

                Comment

                • Cor Ligthert[MVP]

                  #9
                  Re: Query data (SELECT * FROM table) from XML File

                  Marc,
                  Well, it doesn't work so well with huge volumes...
                  >
                  What are in your idea huge volumes, that is very subjective you know?

                  Cor

                  Comment

                  • Marc Gravell

                    #10
                    Re: Query data (SELECT * FROM table) from XML File

                    What are in your idea huge volumes, that is very subjective you know?

                    Oh absolutely! That is exacatly why I used a vague term like "huge".
                    Especially if we include some behemoths on x64 with tons of memory.
                    As we both know, it depends on too many factors to even go into - but
                    either way, a streaming API will scale effortlessly, where-as with an
                    in-memory answer we need to ask "how big"?

                    But I also agree that streaming APIs aren't necessarily the easiest
                    from an OO point of view, unless you are just doing aggregates etc.

                    Marc


                    Comment

                    Working...