cancel
Showing results for 
Search instead for 
Did you mean: 

Error in XML Parsing

Former Member
0 Kudos

Hi Experts,

We have a JDBC to FILE scenario.

In SXMB_MONI, the XML structure is like this :

<row>

<F1>No</F1>

<F2>2006-05-15 00:00:00.0</F2>

<F3>Ball Screw Inspection Tool - see ECM HS-060004-ECM</F3>

</row>

In RWB, it becomes like this:

<row>

<F1>No</F1>

<F2>2006-05-15 00:00:00.0</F2>

<F3>Ball Screw Inspection Tool - see ECM HS-060004-ECM& # x 0 ;</F3>

</row>

It is a simple one to one mapping. I dont know why it adds these special characters at the end.

Please help.

Regards.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Nagasatya,

Goto payload in MONI and right click on it. Goto View Source. Here you will be able to see if special characters are present in the source.

Regards,

Gautam Purohit

Former Member
0 Kudos

Hi,

Thanks for the replies guys. I did what you guys said and found that there are these four characters at the end which are not at the source(database). How do we remove these? Can we do this using UDF? It only happens to this field. The remaining fields are fine.

Regards.

stefan_grube
Active Contributor
0 Kudos

> I did what you guys said and found that there are these four characters at the end which are not at the source(database).

Yes, it is in the database. It is a hex zero character. A bad program added that value.

hex 0 serves in some program languages (eg. C) as string delimeter.

> How do we remove these? Can we do this using UDF? It only happens to this field. The remaining fields are fine.

You cannot do graphical mapping with this character, so you need a Java mapping to remove the hex 0 character (or the & representation & # x 0) from XML stream.

A better solution is: Find the error in the program, which creates the entries in DB and repair data in DB.

Regards

Stefan

Former Member
0 Kudos

Hey Stefan,

I consulted the database guys and it seems they are reluctant to change the data over there.

So I had to use Java Mapping and this is the code that I am using.

/*

  • Created on Apr 8, 2010

*

  • To change the template for this generated file go to

  • Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments

*/

package PI_HEX_MAPPING;

/**

  • @author pidadm

*

  • To change the template for this generated type comment go to

  • Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments

*/

import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.io.OutputStream;

import java.io.OutputStreamWriter;

import java.util.HashMap;

import java.util.Map;

import java.util.regex.Matcher;

import java.util.regex.Pattern;

import com.sap.aii.mapping.api.StreamTransformation;

import com.sap.aii.mapping.api.StreamTransformationException;

public class HEX_MAPPING_CLASS implements StreamTransformation {

private Map param = null;

public void setParameter (Map param) {

this.param = param;

if (param == null) {

this.param = new HashMap();

}

}

public void execute(InputStream inStream, OutputStream

outStream) throws StreamTransformationException{

try{

BufferedReader in = new BufferedReader(new

InputStreamReader(inStream));

BufferedWriter out = new BufferedWriter(new

OutputStreamWriter(outStream));

// The pattern matches control characters

Pattern p = Pattern.compile("#x0");

Matcher m = p.matcher("");

String aLine = null;

while((aLine = in.readLine()) != null) {

m.reset(aLine);

//Replaces control characters with an empty string.

String result = m.replaceAll("");

out.write(result);

out.newLine();

}

in.close();

out.close();

}catch(Exception e){

e.printStackTrace();

}

}

}

This still throws me an error.Any help would be greatly appreciated.

Regards.

Former Member
0 Kudos

>I consulted the database guys and it seems they are reluctant to change the data over there.

>So I had to use Java Mapping and this is the code that I am using.

the problem is: how do you know in which fields this error will also occur ? Maybe also in other structures/fields which are read from this database, in other mappings ? So this isolated workaround does not make much sense. Because you do not even know that the issue is fully solved then. Maybe it will popup somewhere else again.

So better fix the problem where it originates. As PI developers we should try to reject stupid workarounds which are caused by wrong input data whereever possible. So often we can read topics here in SDN about issues which are caused by erroneous sender systems (e.g. sending invalid XML, wrong encoding, whatever). PI was not invented to fix the errors of the sender systems. If we do that in PI, we will end up with a system which is hard to maintain and understand, because we are fixing strange things from sender systems.

=> insist on correct input data in this case.

CSY

Former Member
0 Kudos

Hey CSY,

I totally agree with you.

The problem with the data here is, it is gathered from a number of other databases and tables from different sources. This is the only way I can do it right now. Can you please tell me what am I doing wrong in the program?

Regards.

stefan_grube
Active Contributor
0 Kudos

It is too complicated

just read input stream byte for byte, check for byte 0, ignore this, all others send to output strem.

3 lines of code

stefan_grube
Active Contributor
0 Kudos

sorry, ignore my last answer.

Edited by: Stefan Grube on Apr 14, 2010 10:32 AM

Former Member
0 Kudos

Hey guys,

Thank you very much for the help.

I resolved the issue without using mapping.

What I did was, in the sender JDBC channel, in the SQL statement, I used REPLACE function for the field causing the problem in order to remove the hex 0 character with an empty string and now it works like a charm.

Regards.

Edited by: Nagasatya Devarakonda on Apr 22, 2010 5:07 PM

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

Can you download HEX software and save the message from moni and try to open in HEX and see if there are any special characters.

moni uses explorer to display XML. Ideally it should show the same thing in both.

which browser are you using to open RWB?

Regards,

Anirudh