Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

How would do you handle this?

 
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two applications use xml for data exchange. The xml's use namespaces and there is a possibility that the prefixes could be changed at times. How would you handle the parsing functionality especially if it mainly used xpath for searching nodes and getting values.

Thanks in advance.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prefix changes doesnot affect any functionality.
 
Manjunath Subramanian
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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".
 
this is supposed to be a surprise, but it smells like a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic