• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Anyone know Linq to XML?

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    #11
    Originally posted by Durbs View Post
    Was just Googling performance following themistry's post as was thinking i don't know how this data will grow:

    http://www.nearinfinity.com/blogs/pa...linq_to_sql_vs

    Guess i'll probably stick to the Reader just in case.
    Interesting to see those performance figures.

    Comment


      #12
      I haven't used any of .Net's XML stuff in a few years, so I don't know exactly what it supports or if I'm describing something that has already been referred to, but a good approach for large XML sources that don't need to be available in their entirety is a hybrid SAX/DOM approach.

      A SAX parser reads the stream of source data and fires off events for interesting moments such as the start and end of an element, attribute or text node; you subscribe to those events and thereby build a DOM that only contains those parts of the source data that are of interest to you. Then you can query that much-simplified DOM via XPath or Linq in whatever way you choose, without incurring the memory burden of parsing the entire source data into a DOM.

      Of course you may be able to do everything in the SAX event handlers, which is possibly FTW, but probably more trouble than it's worth: a two-step process is almost certainly more maintainable, as well as easier to build.

      Probably off-topic, but this also comes in handy with non-XML data such as CSV: one can write a parser for that data that generates SAX events, such that a DOM can be constructed from a non-XML source

      I remember a kerfuffle developing about this on certain mailing lists in the late 90s or early 00s when some purists argued that it was a corruption of the pure spirit of XML to suggest that such techniques should be used to allow non-XML data to be made use of via APIs designed for XML. My attitude was and is: FFS

      EDIT: having perused the link above, it looks like XMLReader is roughly similar to SAX; I'm not sure I would have chosen MS's approach myself, as that example suggests that you have to execute decision-making code for every moment of potential interest rather than only subscribing to those events that are of actual interest, but nonetheless it appears to get around the memory problem and is presumably a widely-used technique.
      Last edited by NickFitz; 18 February 2010, 05:17.

      Comment


        #13
        NickFitz, as valuable as your input is, you really must get some sleep occasionally. Four in the morning, my word!

        Comment


          #14
          Originally posted by lightng View Post
          Ahhh Lambda expressions.

          Bit of a mouthful in programming terms, but try...


          VersionStatus = version.Element("Properties").Elements("Property") .Where(Function(i) i.Attribute("name").Value = "Version Status").Value
          This is why code has gone backwards. How inelegant is that. Object oriented nightmare. Not knocking lightng, you didn't write linq.

          That said, nice one for taking the time to post something on here that works.
          Knock first as I might be balancing my chakras.

          Comment


            #15
            Originally posted by suityou01 View Post
            This is why code has gone backwards. How inelegant is that. Object oriented nightmare. Not knocking lightng, you didn't write linq.

            That said, nice one for taking the time to post something on here that works.
            That's why I prefer Xpath queries. Far more readable. Linq does have its uses but it's not the magic pill Microsoft would like us to believe.

            Comment


              #16
              Originally posted by lightng View Post
              That's why I prefer Xpath queries. Far more readable. Linq does have its uses but it's not the magic pill Microsoft would like us to believe.
              Now XPath, mans tool.
              Knock first as I might be balancing my chakras.

              Comment


                #17
                Originally posted by suityou01 View Post
                Originally posted by lightng View Post
                Originally posted by suityou01 View Post
                This is why code has gone backwards. How inelegant is that. Object oriented nightmare. Not knocking lightng, you didn't write linq.
                That's why I prefer Xpath queries. Far more readable. Linq does have its uses but it's not the magic pill Microsoft would like us to believe.
                Now XPath, mans tool.
                XPath FTW!

                It's always struck me as odd that MS, apparently responding to the fact that many programmers are confused by the set-theoretical aspects of XPath, offer Linq instead, which seems to be a bastardisation of the set-theoretical query language SQL

                However, I strongly disagree with any knocking of lambda functions. For a start they have nothing to do with object-orientation; and for a finish, they are one of the most gloriously powerful constructs in the field of computation. Combine them (as is only natural) with Currying, and they make it feasible to completely eradicate control structures, which are the source of the vast majority of bugs

                I love the smell of functions returning functions that return functions in the morning

                Comment


                  #18
                  Originally posted by NickFitz View Post
                  I love the smell of functions returning functions that return functions in the morning
                  "WTF does this do?"

                  A code review comment from someone reading one of my curried javascript constructions. Most people find these difficult to read, and unless they were raised on functional programming, I do understand why.

                  Comment


                    #19
                    Originally posted by NickFitz View Post
                    However, I strongly disagree with any knocking of lambda functions. For a start they have nothing to do with object-orientation; and for a finish, they are one of the most gloriously powerful constructs in the field of computation. Combine them (as is only natural) with Currying, and they make it feasible to completely eradicate control structures, which are the source of the vast majority of bugs
                    I too was going to post something similar in disgust to SY01, however - you worded it better than I.

                    Don't knock what you don't understand

                    TM
                    Last edited by themistry; 19 February 2010, 13:35.

                    Comment

                    Working...
                    X