cancel
Showing results for 
Search instead for 
Did you mean: 

XPath in Java Mapping

milan_10
Participant
0 Kudos

Hello,

I'd like to ask you if and how it is possible to use XPath expressions in Java Mapping. There is a way with Xalan but SAP is using their own XML parser...

Many Thanks,

Milan

Accepted Solutions (0)

Answers (1)

Answers (1)

henrique_pinto
Active Contributor
0 Kudos

In Java mapping, you have to explicitely parse the XML.

If you want to use XALAN (for Java 1.4, pay attention to that), you can use the .jar in the mapping development and then include it as an imported archive in Integration Repository.

Regards,

Henrique.

milan_10
Participant
0 Kudos

Hello Henrique,

are you sure that there isn't a way how to do that with default (SAP) parser?

Many thanks,

Milan

bhavesh_kantilal
Active Contributor
0 Kudos

You can.. Xpath is used to pull out the value of a field in the XML and the same thing can be done with the java Parser ( DOM or SAX ). Not sure what you mean here by a SAP Parser.

Can you let us know the exact requirements or am I talking senseless stuff here?

Regards

Bhavesh

milan_10
Participant
0 Kudos

Hello Bhavesh,

I'd like to create a mapping XML file where will be the mapping described. So for example take the value of elemnt A, put it in element B in reasult message. The incommig message will be parsed by SAX of course, because of the memory, but this mapping XML I'd like to parse in DOM way and I also would like to use XPath for finding stuff.

Nice isn't it?

Milan

henrique_pinto
Active Contributor
0 Kudos

actually he can't use XPath with Java 1.4 DOM and SAX based parsers.

For example, suppose you want to get the value of field <value> of XML below:

<xml>
  <data>
    <field>F001</field>
    <value>123</value>
  </data>
</xml>

In DOM parser, after parsing, you do something like:

...
Node xml = doc.getDocumentElement();
xml.normalize();
String value = xml.getFirstChild().getChildNodes().item(1).getNodeValue();

With XALAM, you do something like:

doc.getNoveValue("xmldatavalue");

They work pretty differently.

Regards,

Henrique.

bhavesh_kantilal
Active Contributor
0 Kudos

Henrique,

Thanks for that explanation. I now see the difference.. Pooh, looks likes there is some reading for me to do over the weekend.

Regards

Bhavesh

PS : Btw, did you check out the number of articles that have come out on 7.1 over the course of this week? You now know what my weekend plans are Have a good day!

milan_10
Participant
0 Kudos

Hi Henrique,

actually I can: please check this out: http://www.exampledepot.com/egs/org.w3c.dom/xpath_GetAbsElem.html

And it will be very easy for me to create needed xpath expression during mapping which I need. I also think about looking for elements by tag name somethink like this:

NodeList list = doc.getElementsByTagName("TagName") limitation are that I cannot have the same name for incomming elements because then it will returm all of them and I will have to do more logic there.

With XPath it will be more easy because you have more control where to look for element.