This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes XML parse error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XML parse error" Watch "XML parse error" New topic
Author

XML parse error

venkatesh warlu
Ranch Hand

Joined: Mar 11, 2008
Posts: 33
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

Joined: Mar 11, 2008
Posts: 33
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

Joined: Mar 22, 2000
Posts: 12760
    
    5
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

Joined: Mar 11, 2008
Posts: 33
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

Joined: Mar 11, 2008
Posts: 33
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

Joined: Mar 22, 2000
Posts: 12760
    
    5
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
 
subject: XML parse error
 
Similar Threads
Reading xml file
XML parser with good performance
SAX Parser
SAXParser doesnt parse swedish characters properly
Parsing data file to XML?