 |
| 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
|
|
|
|

September 15th, 2005, 11:16 AM
|
|
Authorized User
|
|
Join Date: Sep 2005
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

September 15th, 2005, 11:24 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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
|
|

September 15th, 2005, 11:29 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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
|
|

September 15th, 2005, 11:31 AM
|
|
Authorized User
|
|
Join Date: Sep 2005
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

September 15th, 2005, 12:43 PM
|
|
Authorized User
|
|
Join Date: Sep 2005
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|
 |