0

I receive an XML file through Websphere Message Broker, but when I process it with Java it gives me a non formatted file in the output.

the XML input file :

<?xml version="1.0" encoding="UTF-8"?>
<article href="http://www.ensa-agadir.ac.ma/arti234">
    <titre>application de web sémantique</titre>
    <nombrePages>12</nombrePages>
    <auteur rond="principale">
        <nom>Hassani</nom>
        <prenom>Jamal</prenom>
        <etablissement>Ensa-Agadir</etablissement>
    </auteur>
</article>

Java compute (for processing message) :

MbMessage outMessage = new MbMessage();
MbMessageAssembly outAssembly = new MbMessageAssembly(assembly, outMessage);
MbElement omroot = outMessage.getRootElement();
MbElement xmlnsc = omroot.createElementAsLastChild ("XMLNSC");
MbElement valueEl = xmlnsc.createElementAsFirstChild(MbElement.TYPE_VALUE, "VALUE", 
                new String ((byte[])message.getRootElement ().getFirstElementByPath("/BLOB/BLOB").getValue()));
out.propagate(outAssembly);

the XML output file : enter image description here

like it's not recognizing any utf-8 characters like : quotes or < and > etc... so I think that converting the incoming file to text will solve the problem. But I don't know how to do it, or if it's the best solution.

Do you have any idea about this ? Thank you :)

Edit : the message shouldn't just be escaped, it should be converted and well encoded to the output.

4 Answers4

1

Well, I've found the solution. I had to choose the XMLNSC Parser in the HTTP Input Node instead of the default one which is the BLOB Parser, and I had to change my Java Compute code :

MbMessage outMessage = new MbMessage();
MbMessageAssembly outAssembly = new MbMessageAssembly(assembly, outMessage);
MbElement omroot = outMessage.getRootElement();
MbElement xmlnsc = omroot.createElementAsLastChild ("XMLNSC");
MbElement valueEl = xmlnsc.createElementAsFirstChild(MbElement.TYPE_VALUE, "VALUE", 
            new String ((byte[])message.getRootElement ().getFirstElementByPath("XMLNSC/article/titre").getValue()));

// And use getFirstElementByPath field by field not trying to display all of it like text

out.propagate(outAssembly);

Thank you guys :)

0

The issue here is that you are creating a single xml element whose value is the entire input message as a blob.

Your best bet would be to modify the input node properties to use the xmlnsc parser.

Alternatively you need update your java to parse the blob using CreateElementAsLastChildFromBitstream()

There's an example here:

http://publib.boulder.ibm.com/infocenter/wmbhelp/v8r0m0/topic/com.ibm.etools.mft.doc/ac30350_.htm

Dave
  • 633
  • 4
  • 6
0

You can actually even simplify it a bit more, there is a method Mbelement.getValueAsString() which saves you having to use a cast to byte array and the String constructor.

So for example your

MbElement valueEl = xmlnsc.createElementAsFirstChild(MbElement.TYPE_VALUE, "VALUE", new String( (byte[]) message.getRootElement().getFirstElementByPath("XMLNSC/article/titre").getValue()));

Becomes:

MbElement valueEl = xmlnsc.createElementAsFirstChild(MbElement.TYPE_VALUE, "VALUE", message.getRootElement().getFirstElementByPath("XMLNSC/article/titre").getValueAsString());

Dave
  • 633
  • 4
  • 6
-1

im not well in java, but i observe that the symbol are transformed with html entities values see this link http://www.w3schools.com/tags/ref_entities.asp you can get all entities.

Don't vote-down i just help him what i observed up-to my knowledge.

Civa
  • 2,058
  • 2
  • 18
  • 30
  • Thank you. yeah sure I can get all entities and understand them. But what I need is to convert them to set an output and correct XML message –  Mar 13 '13 at 18:51
  • see this article you get your answer http://stackoverflow.com/questions/7505387/im-looking-for-a-java-html-encoder – Civa Mar 13 '13 at 19:01
  • can you tick answer if my post is use full to you. – Civa Mar 13 '13 at 19:13
  • Don't worry, I will if it's useful :) –  Mar 13 '13 at 19:22
  • And it's about parsing not escaping –  Mar 13 '13 at 19:40