Tom said:
I've not looked at the implementation of the .NET XPath classes - so, I can't
be sure how they are implemented. Though, there are basically two ways to
work with XML data, and that is DOM which loads the entire XML document model
into memory or using an XmlReader to stream the data. But, my comment had not
to do with that anyway. It was derived from comments made further up the
thread, where things like split and File.ReadAllLines were being discussed.
Right, thats was before the OP stated the XML details of what he was
doing.
As for the size of files being less of a concern... That must be very domain
specific, because it's something I have to worry about quite often - so I take
it seriously when I see entire files slurped up in one fell swoop in
production code
I've seen servers brought to their knees from this
seemingly simple method of reading data.
I was speaking in general, dealing with larger files today is
generally not given a 2nd thought until one has system performance issues.
I'm not saying I never use stuff like File.ReadAllLines - but, I try to
carefully weigh the alternatives before I make this sort of decision.
right.
You think that XPath syntax is more straight forward then the simple statement
above? I'm not saying don't learn XPath, because there are times you need it
even with LINQ - but, LINQ is definately easier and more straight forward.
The above does look easy. I don't know LINQ, but in general, I am use
to the slash "/" path method, its more standardize method and it
directly applies to tag based data representations. Its used in other
technologies too, like CSS, DOM and now that Microsoft officially
supports jQuery in ASP.NET, XPATH DOM element look ups is supported. I
don't you will be able to use LINQ on the client side.
Anything is doable. But why reinvent the wheel? Use the tools that
Thanks for highlighting LINQ as an alternative method.
I just looked up LINQ. For the general public, here is a good link:
http://msdn.microsoft.com/en-us/library/bb397897.aspx
Introduction to LINQ
Comparison of XPath and LINQ to XML
http://msdn.microsoft.com/en-us/library/bb675156.aspx
Is it for VS2008 and .NET 3.5 only?
Off hand, it appears like MS wanted to get SQL into the XML lookup
picture. A good idea to leverage the database oriented developer
community.
How about a more "declarative" statement that takes most design
considerations into account?
Let Series equal list of "series" tags in document "TVShows.xml"
with preferred advanced reading options
Enable File Mapping if size over 500m bytes
FoundTagEvent = AddressOf FindEpsiodesPerSeries
FinishEvent = AddressOf GotAllSeries
and with ftors (functors) one can put the events in the statement too.
FoundTagEvent = function(item)
if item.cancel then
return false ' skips item
end if
return true
end function
and with refactoring, it can be added to application library:
series = MethodName("series","tvshows.xml")
<g>