[Home] [By Thread] [By Date] [Recent Entries]
Hi Michael,
Thank you very much for your thorough response even though I don't understand most of them.
All I was trying to do was to parse some simple html pages (http://forums.sun.com/thread.jspa?threadID=5343084&tstart=30) which has worked in an unstructured coding manner. I got stuck with what appears to be an I/O issue and has turned to other XML conversion tool such as TagSoup (requires Saxon 6.5.5).
I am reluctant to embark on what appears to be very different to simple JDOM XPath environment and do not see a need to use XSLT just yet. Nevertheless, you extra effort has been very much appreciated still.
Cheers,
Jack
From: Michael Kay <mike@s...> To: Jack Bush <netbeansfan@y...>; xml-dev@l... Sent: Wednesday, 5 November, 2008 8:13:59 PM Subject: RE: How to parse XML document with default namespace with JDOM XPath The book you are quoting is very old information. Where it says that you can do something, it's probably right, but where it says that you can't, it may well be wrong..
Frankly, I forget exactly what's in Saxon 6.5.x because it's so long ago - I know JDOM was already supported back then but I don't remember the details of the API. I do recall, that as Elliotte says in his book, the Saxon API for invoking XPath was pretty clumsy in those days (because it was designed primarily for internal use by the XSLT engine, not as a user-facing interface). I would use a more recent release.
But the code you gave us wasn't even trying to use Saxon, it was using the XPath engine within JDOM, using a JDOM API that I'm not very familiar with, and therefore I can't tell you why it isn't working.
My own preference for this kind of coding would be to use Saxon's s9api interface, documented at
http://www.saxonica.com/documentation/javadoc/net/sf/saxon/s9api/package-summary.html
There are sample applications in the saxon-resources download (from SourceForge). It includes an example of XPath with JDOM like this:
public void run() throws SaxonApiException {
// Build the JDOM document org.jdom.input.SAXBuilder jdomBuilder = new org.jdom.input.SAXBuilder(); File file = new File("data/books.xml"); org.jdom.Document doc; try { doc = jdomBuilder.build(file); } catch (org.jdom.JDOMException e) { throw new SaxonApiException(e); } catch (IOException e) { throw new SaxonApiException(e); } Processor proc = new Processor(false); DocumentBuilder db = proc.newDocumentBuilder(); XdmNode xdmDoc = db.wrap(doc); XPathCompiler xpath = proc.newXPathCompiler(); XPathExecutable xx = xpath.compile("//ITEM/TITLE"); XPathSelector selector = xx.load(); selector.setContextItem(xdmDoc); for(XdmItem item : selector) { XdmNode node = (XdmNode)item; org.jdom.Element element = (org.jdom.Element)node.getExternalNode(); System.out.println(element.getValue()); } } (The method getExternalNode() was added in Saxon 9.1.0.2 and is not yet in the published Javadoc)
You would probably want to add a call
xpath.declareNamespace("prefix", "uri")
before the compile() call.
Michael Kay
http://www.saxonica.com/
From: Jack Bush [mailto:netbeansfan@y...]
Sent: 05 November 2008 03:48 To: Michael Kay; xml-dev@l... Subject: Re: How to parse XML document with default namespace with JDOM XPath
Search 1000's of available singles in your area at the new Yahoo!7 Dating. http://au.rd.yahoo.com/dating/mail/tagline1/*http://au.dating.yahoo.com/?cid=53151&pid=1011.
[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] |

Cart



