Namespaces with JDOM
Posted: Jul 27, 2004 2:32 AM
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