Project

Profile

Help

Support #5147

closed

Saxon with Json Payload fails to fetch xpath

Added by Trinath Reddy over 2 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
High
Assignee:
Category:
-
Sprint/Milestone:
-
Start date:
2021-10-27
Due date:
% Done:

0%

Estimated time:
Legacy ID:
Applies to branch:
Fix Committed on Branch:
Fixed in Maintenance Release:
Platforms:

Description

Dear Colleagues,

This is Trinath from SAP Labs. We are using SaxonEE library for Xpath processing in our product.

The payload used is Json and we wanted to fetch XPath for Json payloads as well. The error is:

Content is not allowed in prolog., cause: javax.xml.xpath.XPathExpressionException: Failure converting a node of class javax.xml.transform.sax.SAXSource: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.

We are getting this issue in SaxonEE-9.9 version

Could you please provide us some insight into this problem. Is it a known issue, can we expect a fix for this in the upcoming releases, or is there any other way to avoid this.

In our stack, we have Apache Camel in our runtime, SaxonEE as XSLT processor with OSGI (Karaf containers)

Thanks in advance Best Regards, Trinath SAP Labs

Actions #1

Updated by Michael Kay over 2 years ago

Well, it looks like you're supplying JSON to an API that expects XML (specifically, a SAXSource). How are you running the XPath evaluation (what API calls are you making?)

Actions #2

Updated by Trinath Reddy over 2 years ago

Hi Michael,

As mentioned above we are using Camel and corresponding tag is as below.

<camel:xpath documentType="javax.xml.transform.sax.SAXSource" factoryRef="saxonEEXpathFactory" resultType="java.lang.String">apply(concat#3, ["a", "b", "c"])</camel:xpath>

-Trinath.

Actions #3

Updated by Michael Kay over 2 years ago

Thanks. I'm afraid we're not familiar with Camel and I've no idea how Camel will interpret this in terms of calling the Saxon API underneath.

The information given at https://wiki.apache.org/confluence/display/CAMEL/XPath is very XML-oriented and suggests that Camel is using the JAXP API javax.xml.xpath.XPathFactory which of course hasn't been updated since XPath 1.0 and is therefore entirely focused on querying XML.

Unless someone who knows Camel can suggest another way of doing this, you may be out of luck. We can help you using XPath to query JSON at the level of telling you how to use the Java API, but only the Camel support people can tell you whether it's possible within Camel.

Or perhaps you can find a way to wrap the JSON payload in an XML wrapper and pass that to the Camel API? If you can do that, XPath 3.1 is quite capable of parsing the JSON within the wrapper and then querying it.

Actions #4

Updated by Michael Kay over 2 years ago

  • Tracker changed from Bug to Support

Reclassifying as "support" rather than "bug" because there is no evidence of a Saxon bug here. (But I'm not confident that we'll be able to offer much help as the problem appears to be in the Camel integration of Saxon, rather than in Saxon itself.)

Actions #5

Updated by Michael Kay over 2 years ago

  • Status changed from New to Closed
  • Assignee set to Michael Kay

Closing this, as there's nothing more we can do. Please feel free to re-open if there's further information, or if you identify a path forward with Camel.

Please register to edit this issue

Also available in: Atom PDF