0

I am facing a situation while using IIB v10 where a SOAP web service is sending XML response that contains both English and REVERSED Arabic in the same XML element.

Example:

<note>
  <to>Tove   رمع</to>
  <from>Jani  ريمس</from>
  <heading>Reminder</heading>
  <body>Don't forget me this weekend!</body>
</note>

It should looks like this

<note>
  <to>Tove   عمر</to>
  <from>Jani  سمير</from>
  <heading>Reminder</heading>
  <body>Don't forget me this weekend!</body>
</note>

So I already prepared some Java code that takes a string , split it as words in a string array and check if a word is an arabic word then it will reverse it then re-concatenate the string.

The issue is that the backend response is a bit large and I need to loop over each element in the XML tree so is there any way in the Java compute Node that allows traversing each and every element in the tree and get its value as a string ?

JoshMc
  • 10,239
  • 2
  • 19
  • 38
Geeky Omar
  • 44
  • 9
  • I'm not at all an expert on right to left languages, but I'm asking myself this question : the fact that the arabic part of the string looks backwards, does it mean that the XML string is backwards ? I mean that "looking backwards" and "being bacwards" are two different concepts. I expect the index zero of an arabic string to be the rightmost character once printed, so the XML rendering of the string, being naturally left to right, might look backwards. But isn't it the job of a presentation layer to make it right, and not that of the XML engine ? Just asking, again, not an expert. – GPI Jul 08 '21 at 11:43
  • Dear @GPI , The issue is that this XML is coming from some legacy system which I am not able to adapt or even investigate the issue from its side. Maybe you are right but I still need a solution from Middleware side – Geeky Omar Jul 11 '21 at 16:00

1 Answers1

1

Recursion is your friend. Invoke following function with the root element:

import com.ibm.broker.plugin.MbElement;
import com.ibm.broker.plugin.MbException;
import com.ibm.broker.plugin.MbXMLNSC;

public void doYourThing(MbElement node) throws MbException {
    MbElement child = node.getFirstChild();
    while (child != null) {
        int specificType = child.getSpecificType();
        if (specificType == MbXMLNSC.FIELD) {
            String value = child.getValueAsString();
            // Do your thing
        }
        doYourThing(child);
        child = child.getNextSibling();
    }
}
Daniel Steinmann
  • 2,119
  • 2
  • 15
  • 25
  • Thank you Mr. Daniel it solved my issue. I just want to add an edit as "equals" is used to compare strings instead we will have to use "==" operator. – Geeky Omar Jul 12 '21 at 15:16
  • @GeekyOmar: Of course you are right, I corrected the answer. I made this mistake because I simplified some code I already had. – Daniel Steinmann Jul 13 '21 at 10:29