Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XML parse error

 
venkatesh warlu
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys i have a program which will generate a .xml file which has many fields got from db2 database. I am writing the .xml file using ISO-8859-1 format. But when i open the file in excel sheet it shows a message stating xml parse failed. what should i do for this. ? can anyone help me regarding this. I tried in utf-8 and utf-16 format still the file is not opening due to some junk characters in it. Please help me get rid of this problem .

Thanks in advance.
 
venkatesh warlu
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am actually writing the xml file by appending the anchor tags using string buffer class. Tell me if this is the correct way to write the file or is there any other way i can create a proper xml file. I am getting data from db2 database as result set and storing it as strings. Now i need to write these strings in xml format. Please help me out of this. I am new to java and xml.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13047
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is nothing wrong with building an XML document with normal String methods, I do it all the time.

Several alternatives exist but directly writing Strings to an output stream is the fastest.

One source of junk characters is Microsoft word "smart punctuation" - what is writing the data into the database?

When I get bad characters in XML I use a programmer's editor to see the actual hex values in the document.

Bill
 
venkatesh warlu
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks bill

Help me one more thing. Suppose i have the junk characters in one particluar string. Then is there any method to take out the ascii values alone from it. so that others get filtered out. I think regex will help me out. but i m unable to frmae out the code . please suggest some code for this.
 
venkatesh warlu
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks bill

Help me one more thing. Suppose i have the junk characters in one particular string. Then is there any method to take out the ascii values alone from it. so that others get filtered out. I think regex will help me out. but i m unable to frame out the code . please suggest some code for this.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13047
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this example, we replace a crlf sequence with a single lf character



Where modS is the String to be modified and crlfRep is defined:



You need a Pattern (see java.util.regex) for every sequence that needs to be replaced. No new String is created if the Pattern is not found so this is faster than you might think.

Bill
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic