Win a copy of Microservices Testing (Live Project) this week in the Spring forum!

ke zhang

Greenhorn
+ Follow
since Jan 28, 2003
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by ke zhang

Originally posted by Manjunath Subramanian:
Can you pls ellaborate a little?

Let's consider this case.

I have an xpath for a element as ns1:e1/ns2:e2/ns3:e4. So I use this path to parse this element. Now if the prefixes changed to nsp1, nsp2 and nsp3 for ns1, ns2 and ns3 respectively my code will not work since the actual path now is nsp1:e1/nsp2:e2/nsp3:e3.

Am I making sense or am i missing something here.

Thanks for your response.



XPath evaluator provides API that mapping namespace to prefix.
For example, jdom XPath class has a method "void addNamespace(java.lang.String prefix, java.lang.String uri) ", XPath interface in jdk1.5.0 has a method "void setNamespaceContext(NamespaceContext nsContext)".

When programing, don't concern about what prefix is used in input xml, just define your own prefix to namespace mapping and use your own prefix in code. That is ,if you map prefix "ns1" to url "http://sample.org/" by using XPath API(for example: xpath.addNamespace("ns1", "http://sample.org/") ,no matter what is the real prefix is in input, your xpath expression can only use "ns1".