on 07-14-2008 10:27 AM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can Anyone help me clearly on this Issue?
How to Solve this?
if any one have ..Plz provide me with Java Coding?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
24 | |
12 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.