The Artima Developer Community
Sponsored Link

Java Answers Forum
Namespaces with JDOM

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Abhishek Ranjan

Posts: 1
Nickname: abhishekr
Registered: Jul, 2004

Namespaces with JDOM Posted: Jul 27, 2004 2:32 AM
Reply to this message Reply
Advertisement
Hi,

I need some help with JDOM. I am trying to use XPath in JDOM. Can I set the namespace without setting a prefix. I know there is an API which is getNamespace(java.lang.String uri). My code looks something like this :

XPath xpath = XPath.newInstance("/PrescriptionHeader/id/@root");
org.jdom.Namespace ns = org.jdom.Namespace.getNamespace("urn:hl7-org:v3");
xpath.addNamespace(ns);
Stri ng str = (String) xpath.selectSingleNode(document);

This however does not return the desired result, however if
I tweak the code to look like this:

XPath xpath = XPath.newInstance("/foo:PrescriptionHeader/foo:id/@root");
org.jdom.Namespace ns = org.jdom.Namespace.getNamespace("foo","urn:hl7-org:v3");
xpath.addNamespace(ns) ;
String str = (String) xpath.selectSingleNode(document);

This returns the proper result. I just want to know why the first solution isn't working.

I am using JDOMB-10

Any help would be appreciated.

Thanks & Regards,
Abhishek

Topic: running batch files from java Previous Topic   Next Topic Topic: pixelgrabber()

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use