cancel
Showing results for 
Search instead for 
Did you mean: 

Blanks in Java Mapping

Former Member
0 Kudos

Hello experts,

we have a 2 step mapping in our scenario. Firstly we use the graphical mapping and set blanks to all fields that are not filled.

So we have a structure like

<head></head>
<pos1>
  <value1>100</value1>
  <value2>         </value2>
</pos1>
<pos2>
  <value1>   </value1>
  <value2>         </value2>
</pos2>

When I do a java mapping after that, he ignores all blanks and makes a structure like:

<head></head>
<pos1>
  <value1>100</value1>
  <value2></value2>
</pos1>
<pos2>
  <value1></value1>
  <value2></value2>
</pos2>

How can I keep the blanks? I tried

DocumentBuilderFactory factory =
                DocumentBuilderFactory.newInstance();
            factory.setIgnoringElementContentWhitespace(false);

in the Java Code, but the blanks are still ignored...

Best regards,

David

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi

setIgnoringElementContentWhitespace works only if you have a DTD to validate it against.

As regarding a solution, the one that comes to mind right away is follow the java map with another message map and once again set the whitespaces.

BR

Answers (3)

Answers (3)

Former Member
0 Kudos

Can Anyone help me clearly on this Issue?

How to Solve this?

if any one have ..Plz provide me with Java Coding?

Former Member
0 Kudos

Hello Sathish,

my code is:

//Create and modify String from input
String input_s = slurp(input);
        	
input_s = input_s.replaceAll("> ", ">#BLANK#");
input_s = input_s.replaceAll(" <"", "#BLANK#<");
        	
input = new ByteArrayInputStream(input_s.getBytes());
        	
//Create DOM parser
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();

//Parse input to create document tree
Document doc = builder.parse(input);


//DO YOUR MAPPING HERE


String doc_s = doc.toString();
doc_s = doc_s.replaceAll(">#BLANK#", "> ");
doc_s = doc_s.replaceAll("#BLANK#<"", " <");
            
RESULT = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + doc_s;

Does anybody have a better solution? It works, but I don't think, that it's the best way to do it.

Regards,

David

EDIT:

Please notice, this can lead to errors, if there are any blanks outside of tags!!!

Edited by: David Claes on Jul 17, 2008 2:32 PM

GabrielSagaya
Active Contributor
0 Kudos
Former Member
0 Kudos

I chose another solution, because a third mapping was not possible due to the structure. I replaced all "> " and " <" with ">#BLANK#" and "#BLANK#<" before parsing and after mapping I replaced it back.

I have to admit, that I'm not very lucky with this solution, but it works quite well...

Thanks anyways,

David

santhosh_kumarv
Active Contributor
0 Kudos

Hi,

1. Why do u require to insert a blank spaces for the fields that are not filled in the graphical mapping and then remove it in the Java mapping. Instead map a empty constant.

2. You can only get a xml node like <value2/> and not <value2></value2>.

If your requirement is to generate a target field always and fill it with the source value if it exists else a blank value use the following.

Check if the source field exists(node function).

a. If exist map the source to the target.

b. If not map a empty constant to the target.

Thanks

SaNv...

Former Member
0 Kudos

Hello both,

I need it because in the file receiver adapter the fields have to be filled with blanks.

However, I do a third graphical mapping...

Thank you!

Former Member
0 Kudos

"However, I do a third graphical mapping..."

If the above was the solution, are you sure you rewarded the right person??