0

I'm trying to update some old code from Velocity 1.7 / VelocityTools 2.0 to 2.2/3.0 versions. During tests I'm processing a XML file with multiple Namespaces (lets say b for book and a for author: <b:book xmlns:b="http://www.test.com/book" xmlns:a="http://www.test.com/author" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> ). The xml is generated from a JAXB class. In the past I could just address this as:

$book=$xmlTool.parse($xmlText).get("b:book") 
$authorName=$book.find("./b:author/a:name")

With the new versions that does not seem to work. The return value from get(...) is always null. It seems, that the XPath is missing the NamespaceContext from the parsed file. If I modify XPath expression in find to search e.g. for local name or if I "inject" (by replacing some code in VelocityTools) the Namespace it works. It also works with old Dom4j/jaxen combination in VelocityTools 2.0.

Modifying the XPath expressions would be very hard (very many templates with different namespaces and use cases). So I could stay with VelocityTools 2.0, but due to some old libraries that might not be working with future versions of the software.

Is there any way to tell XmlTool to inject the Namespace from the root node? There is a bug entry: https://issues.apache.org/jira/browse/VELTOOLS-160 That was closed as not needed, but I don't see, how it should work.

Jens Popp
  • 131
  • 1
  • 12

0 Answers0