cancel
Showing results for 
Search instead for 
Did you mean: 

XML with whitespace over mailadapter - howto delete? JAVA

Former Member
0 Kudos

hello together,

we will receive xml messages over mailadapter. normally the communication partner sends the messages in a good format (no whitespaces between tags). but sometimes it is a bad format like this (caused by outlook preformatting maybe) :

<tag1>

...<tag1.1></tag1.1>

...<tag1.2></tag1.2>

</tag1>

the points '.' will be symbols for blanks or other whitespaces between end-tag of previous node(</tag1.1>) and start-tag(<tag1.2>) of current node in the message. and that is the problem (wrong working of java file).

the difference to a good file:

<tag1><tag1.1></tag1.1><tag1.2></tag1.2></tag1>

the internet browser will show it in xml formatted tags with '+' and '-' and if we have a look at the source code we will find a 'good' file.

so my question: how can i delete the whitespaces between closing and opening tags in java? do anybody know a standard java function to handle this problem?

thanks a lot

alex

Accepted Solutions (0)

Answers (1)

Answers (1)

Shabarish_Nair
Active Contributor
0 Kudos

did you try ...

http://java.sun.com/j2se/1.3/docs/api/java/lang/String.html#replace(char,%20char)

replace(" ","");

maybe it works ... also try a trim() too ...

Former Member
0 Kudos

hi shabarish,

this idea is ok.

but to use the replace or trim function i have to convert the document to string.

<i>(the document will be parsed with 'Document doc = docBuilder.parse(in);'.)</i>

now, your advice: <i>String test = doc.toString().replace(" ","")</i>

but how can i make the string to xml file again to use some node functions on it?

do you know anything to that issue?

thanks a lot

alex

Shabarish_Nair
Active Contributor
0 Kudos

Not much of a java guy i am but can you just look into this thread of sun java. Might lead you to new ideas ...

Former Member
0 Kudos

thank you very much, it works! you are right with new ideas!!!

thanks a lot

alex

Shabarish_Nair
Active Contributor
0 Kudos

Haha .. nice to know that well so next time i get stuck with this i know whom to contact !!!