Reputation: 11
I'm using HANA Cloud Integration to build an Integration Flow (iFlow). However, anyone with any XML experience could potentially help me.
I've built a really simple integration flow that talks to the openweathermap API, pulls in "weather" data, then emails specific data points. This is the XML I am working with below:
<current>
<city id="5913490" name="Calgary">
<coord lon="-114.09" lat="51.05"/>
<country>CA</country>
<sun rise="2016-02-22T14:34:54" set="2016-02-23T01:05:30"/>
</city>
<temperature value="262.098" min="262.098" max="262.098" unit="kelvin"/>
<humidity value="79" unit="%"/>
<pressure value="865.62" unit="hPa"/>
<wind>
<speed value="1.32" name="Calm"/>
<gusts/>
<direction value="262.002" code="W" name="West"/>
</wind>
<clouds value="0" name="clear sky"/>
<visibility/>
<precipitation mode="no"/>
<weather number="800" value="clear sky" icon="01n"/>
<lastupdate value="2016-02-22T14:12:31"/>
</current>
For this the weather
element in the current
root element needs to be extract and the value
field will be used. This is formed by the XPath string /current/weather/@value
The last update field will also need to be passed onto the next process in the integration and can be extracted in the same way.
I created two header properties that are strings called currentConditions
and currentReport
and these point to the XPath attributes /current/weather/@value
and /current/lastupdate/@value
. In XPath the @
refers to an attribute and not an element. Also remember to make these header values so they can be passed to the external service calls. If they are properties they will not be sent to the external processes. However, I get this error:
org.apache.camel.builder.xml.InvalidXPathExpression: Invalid xpath: /current/weather/@value. Reason: 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., 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.
Any suggestions?
Upvotes: 1
Views: 2534
Reputation: 32980
Your XPath expression is OK. The root cause of the error you see is in this nested exception:
org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
It seems that the data you pull from the openweathermap API is not well-formed XML. This often happens if a REST-API sends an error response. You should first verify that API request returns successfully and contains well-formed XML.
Upvotes: 3