[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1398
  • Last Modified:

Program to strip out invalid xml characters

Hello Everyone,

I have an xml file that has invalid characters.  When i try to parse the file it errors out with this error message :

An invalid XML character (Unicode: 0x{2}) was found in the value of attribute "{1}".

I would like for a program to stip out all characters that are invalid.

Your help is very much appreciated.

Thanks,

Venkat
0
gbvreddy
Asked:
gbvreddy
  • 4
  • 2
1 Solution
 
CEHJCommented:
Try cleaning the file:


                  int buf = in.read();
                  if (Character.isISOControl((char) buf)) {
                        System.err.printf("The bad character is %.2h\n" + buf);
                  } else {
                        out.write(buf);
                  }
0
 
CEHJCommented:
Sorry - i meant to write:

int buf = -1;
while ((buf = in.read()) > -1) {
      if (Character.isISOControl((char) buf)) {
            System.err.printf("The bad character is 0x%02X\n", buf);
      } else {
            out.write(buf);
      }
}
in.close();
0
 
gbvreddyAuthor Commented:
Hi CEHJ,

Thanks a lot for the reply. Now, how do I delete that character and write the whole stream back to the file with same name.

Thanks,

Venkat
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
CEHJCommented:
Just create a temp file, delete the original and then rename the temp file as the original
0
 
objectsCommented:
Do you know where the invalid characters are coming from?
0
 
gbvreddyAuthor Commented:
Objects,

They are coming from a database. I solved this problem.

Thanks CEHJ.....

Venkat
0
 
CEHJCommented:
No problem

;-)
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now