473,397 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

How can I run an XPath on a very large file?

My program runs out of memory when I do this:

string filename = @"large.xml";
XPathDocument doc = new XPathDocument(filename);
XPathNavigator nav = doc.CreateNavigator();
XPathNodeIterator iterator = nav.Select("//items/item");
while (iterator.MoveNext()) {
....
}

I get the same behaviour with other XPathDocument constructors too.

Can anyone advise how to do an XPath on an XML stream rather than a document?
Nov 12 '05 #1
2 2054
JerryShea wrote:
My program runs out of memory when I do this:

string filename = @"large.xml";
XPathDocument doc = new XPathDocument(filename);
XPathNavigator nav = doc.CreateNavigator();
XPathNodeIterator iterator = nav.Select("//items/item");
//items/item is one of the worst XPath expressions. Always avoid using
// if you care about perf.
I get the same behaviour with other XPathDocument constructors too.

Can anyone advise how to do an XPath on an XML stream rather than a document?

To select item elements children of items element you don't need
XPathDocument, it can be easily implemented with XmlTextReader.
If you do need XPath, take a look at XPathReader.
--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #2
thanks a lot Oleg. The XPathReader is just the ticket

"Oleg Tkachenko [MVP]" wrote:
JerryShea wrote:
My program runs out of memory when I do this:

string filename = @"large.xml";
XPathDocument doc = new XPathDocument(filename);
XPathNavigator nav = doc.CreateNavigator();
XPathNodeIterator iterator = nav.Select("//items/item");


//items/item is one of the worst XPath expressions. Always avoid using
// if you care about perf.
I get the same behaviour with other XPathDocument constructors too.

Can anyone advise how to do an XPath on an XML stream rather than a document?

To select item elements children of items element you don't need
XPathDocument, it can be easily implemented with XmlTextReader.
If you do need XPath, take a look at XPathReader.
--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com

Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: gael.pegliasco | last post by:
Hi, How are you dear and nice helper :) ? I'm trying to test xpath with this simple program : import xml.dom.minidom from xml.xpath.Context import Context import xml.xpath
14
by: inquirydog | last post by:
Hi- One frusterating thing for me with xsl is that I don't know how to make xslt throw some sort of exception when a value-of path does not exist. For instance, suppose I have the following...
2
by: Ben Fidge | last post by:
Is it possible to sort the result of an XPath "select" query? I need to return a subset of a large xml file, and XPath is the way to go. I'd like to sort this subset afterwards? This seems...
1
by: Rob | last post by:
Hi, I am moving through an XML document using an XPath Navigator, and I'd like to be able to get the xpath expression for the location of the current node from the root node. Any ideas how to...
4
by: Ken Getz | last post by:
Hi. I have an xml file in this format: <strings> <string>Item1</string> <string>Item2</string> <string>Item3</string> <string>Item4</string> </string> I'm looking for the best way to...
3
by: ziggyware | last post by:
Hi All, I have updated my XPath Generator software: XPath Studio .NET. ( http://www.ziggyware.com/downloads.php?cat_id=2 ) Easily select nodes from an xml file to generate XPath statements ...
3
by: werD | last post by:
Hello I have an xml document that im currently using a forward only .net repeater on and using some xpath queries to display the data The xml is quite simple <?xml version="1.0"...
2
by: Bilal | last post by:
Hello, I'm stuck on this problem for quite some time and hope somebody would be able to guide me. Basically, I need to populate a large number of "template" XML files which have all...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.