• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

How would do you handle this?

 
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Prefix changes doesnot affect any functionality.
 
Manjunath Subramanian
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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".
 
reply
    Bookmark Topic Watch Topic
  • New Topic