on 09-15-2009 12:48 PM
Hi experts,
Im folllowing this blog by felin on xl to xml..
im getting an error every time the cell has &...eveything else is fine
pls let em know
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
sample code
protected static void copySource(InputStream in, OutputStream out)
throws IOException {
int c;
while ((c = in.read()) != -1) {
switch (c){
case '&': out.write("&".getBytes()); break;
case '\"': out.write(""".getBytes()); break;
case '\'': out.write("'".getBytes()); break;
case '<': out.write("<".getBytes()); break;
case '>': out.write(">".getBytes()); break;
default: out.write(c);
}
modify the above code for module development accordingly
I suggest you to create a method with one arg inputstream and output another inputstream check condition inside the method by reading character by character from the input stream and replace the special characters(as given above) and copy to return inputstream.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
The blog from felix was intended to show that file adapter can also read excel file. But it still have all these problem (like the & issue). I will suggest you to yse this piece of code in you module so that the junk characters are replaced by SPACE
public String check(String node){
node = node.replaceAll(" ","");
node = node.replaceAll("[^a-zA-Z 0-9]+","");
return node;
}
Regards
suraj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Guys,
My module code has
xmldata ="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n"+ "<ns0:""MT_Test"" ""xmlns:ns0=\"""urn:test:excelfiles"+"\"> \n ";
int a = w.getSheet(0).getRows();
int b = w.getSheet(0).getColumns();
for(int j=1;j<a;j++)
{
for(int i=0;i<b;i++)
{
xmldata = xmldata "\n" "<"w.getSheet(0).getCell(i,0).getContents().toString()">"w.getSheet(0).getCell(i,j).getContents().toString()"</"w.getSheet(0).getCell(i,0).getContents().toString()">"+ "\n";
}
}
xmldata = xmldata" </ns0:""MT_Test"+">";
Now, If cell (2,2) has &... how do i adjust the code?
cos its a string right?
Hi
Edit your code like this;
xmldata ="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n"+ "<ns0:""MT_Test"" ""xmlns:ns0=\"""urn:test:excelfiles"+"\"> \n ";
int a = w.getSheet(0).getRows();
int b = w.getSheet(0).getColumns();
for(int j=1;j<a;j++) {
for(int i=0;i<b;i++) {
*String Content = check (w.getSheet(0).getCell(i,j).getContents().toString());*
xmldata = xmldata "\n" "<"w.getSheet(0).getCell(i,0).getContents().toString()">"Content"</">"+ "\n";
}
}
xmldata = xmldata+" </ns0:""MT_Test"">";
public String check(String node){
node = node.replaceAll(" ","");
node = node.replaceAll("[^a-zA-Z 0-9]+","");
return node;
}
Be sure that this code will replace & from the input. If you want to change & to & edit this section
String Content = check (w.getSheet(0).getCell(i,j).getContents().toString()); with the appropriate methods (as specified by other users)
Regards
Suraj
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.