Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 15th, 2005, 11:16 AM
Authorized User
 
Join Date: Sep 2005
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default Fast XPath

Hi,
i've been using (like you can see in the last topic) a XPath processor for Java, the problem is that it's very slow, because i want to parse a XML file directly from the Internet (from a URL)
I have this code

XPath xpath = XPathFactory.newInstance().newXPath();
xpath.setNamespaceContext(new RBTNameSpace());
InputSource inputSource = new InputSource(uaprof);

String expr = "/rdf:RDF/rdf:Description/prf:component/rdf:Description/prf:Vendor/text()";
String brand = xpath.evaluate(expr,inputSource);

XPath used is

import javax.xml.xpath.XPath;

Is there any different (faster) XPath Class, or should i use Xalan or Saxon ?

I think the problem is when i create a new InputSource with the file.
I know that XTags from Jakarta is very fast, the only problem is that it only work with JSP

Thank you






 
Old September 15th, 2005, 11:24 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

My first guess would be that the response time you are seeing is dominated by the time taken to retrieve the XML file from the remote site and parse it, and therefore your choice of XPath processor (which comes into play only when that process is complete) is going to make very little difference. How big is the file?

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old September 15th, 2005, 11:29 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Incidentally, your import statement only declares the XPath API interface, this doesn't determine which XPath implementation you are using. You're probably using the default one in the JDK (Xalan), but your code wouldn't have to change to use Saxon, you just have to put Saxon on the classpath.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old September 15th, 2005, 11:31 AM
Authorized User
 
Join Date: Sep 2005
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The file is very small, it's less then 20kb (17kb i think)
What i find strange, is that with the Jakarta XTags Lib, it's very fast

 
Old September 15th, 2005, 12:43 PM
Authorized User
 
Join Date: Sep 2005
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, i found the problem
i have several expression to evaluate, and i thought that the file was read in to memory when i wrote
InputSource inputSource = new InputSource(FILE);

But the file is read in each
String brand = xpath.evaluate(expr,inputSource);

Now i change it with a
Document document = builder.parse(new InputSource(uaprof));
On top of the code, then the document is read and each
String brand = xpath.evaluate(expr,document);

Now it's much faster :D
Thanks







Similar Threads
Thread Thread Starter Forum Replies Last Post
fast connect with c# zaghmout C# 0 October 8th, 2008 02:37 AM
Are vbscript classes fast? atwork8 Classic ASP Basics 0 May 3rd, 2008 11:13 AM
I Need Help Guys ... Please fast :> Badie Access ASP 2 May 2nd, 2005 07:00 PM
Fast printing rajanikrishna Pro VB 6 8 November 24th, 2004 09:39 AM
Fast Fourier Transform maniacBS VB How-To 0 December 22nd, 2003 01:24 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.