Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2006

Tip: Looking for answers? Try searching our database.

JDK1.5 Xpath problem

Thread view: 
abcd_68@yahoo.co.uk - 15 Sep 2006 17:12 GMT
Hi there,

I'm using, for the first time, the JDK1.5 Xpath API. I need to find
elements in a Hibernate-generated .hbm.xml file. These files come with
a <!DOCTYPE header mentioning a remote URL. The Xpath parser fetches
the URL from the hibernate.sourceforge site. So far so good.

However, if I unplug the network, I get (after a *long* timeout) a
java.net.SocketException. I looked around and I found out that I have
to define a class implementing EntityResolver to change the default
behaviour (i.e., fetch the DTD over the net) and obtain an InputSource
from it. Something along the lines of:

public class UriTransform implements EntityResolver {
 public InputSource resolveEntity(String publicId, String systemId) {
   return new InputSource(new StringReader(""));
 }
}

Now my problem is: How do I do it? Neither in javax.xml.xpath.XPath nor
in javax.xml.xpath.XPathFactory did I find an appropriate place nor did
I find a method to gain access to the underlying SAX parser. Here's my
code:

XPath xpath = XPathFactory.newInstance().newXPath();
final String expression = "//property";
final String completePath = ... //file path
InputSource inputSource = new InputSource(completePath);
DTMNodeList nodes = (DTMNodeList) xpath.evaluate(expression,
 inputSource, XPathConstants.NODESET);

Any ideas?
TIA
andy
Joseph Kesselman - 15 Sep 2006 18:52 GMT
One way around this is to instantiate the parser yourself, configure it
appropriately, then pass it to the transformer wrapped in a SAXSource.

(There ought to be a way to pass an entity resolver/URI resolver through
the XPath APIs, but I'm having trouble finding it.)


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.