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 30th, 2004, 09:10 AM
Authorized User
 
Join Date: Jul 2004
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default Browsing DOM in Java - Xpath?

Hello,
  back in my ASP days, I got very accustomed to the MSXML objects, and the joy of being able to pull a node out of a document simply by using docObj.selectNodes("/Data/My/Xpath[@id='4']").

  This is great, because you can then use XML for data files, config files and all sorts of loveliness.

  Now I use Java.

  While I have written myself nice classes for validating and transforming XML documents, I have failed to find any exising examples of how to travel around a Document in a java program using XPath. The closest I have found is getElementsByTagName but this is pretty arbitrary, and if, for example, I have a XML document containing 500 individual people, I would have 500 elements called 'FirstName' and 500 called 'LastName' and I would not want to trawl through these manually looking for String matches.

Any ideas, or do I have to write my own XPath class?

holdmykidney
 
Old September 30th, 2004, 10:28 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Firstly, I'd suggest that in Java you consider using JDOM or XOM rather than the DOM, they are much easier to work with, and much more Java-friendly.

Secondly, for any of these object models you'll find a number of XPath processors available. Saxon, for example, offers a Java API that will access DOM or JDOM trees. The XPath processor may come from a different source than the object model implementation.

There's a standard XPath API coming along in JDK 1.5 that's designed to work with any document model, but not everyone supports it yet (it's very new).



Michael Kay
http://www.saxonica.com/
 
Old October 4th, 2004, 09:08 AM
Authorized User
 
Join Date: Jul 2004
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That is exactly what I was looking for - thank you!

holdmykidney





Similar Threads
Thread Thread Starter Forum Replies Last Post
java.lang.ClassCastException: org.apache.xpath.obj ksskumar XSLT 4 December 15th, 2006 03:13 AM
XPath API and DOM Document object nnravi XML 10 May 2nd, 2006 12:24 PM
Java & XPath safin XML 4 September 15th, 2005 06:04 AM
Java Applet that can read XML DOM and display text sankar XML 3 February 16th, 2004 11:16 AM
XML DOM parser in java... recommend, plz sonicDace XML 0 February 3rd, 2004 02:38 PM





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