Solved

how to handle  Encoding Format ,XML Parsing Error: not well-formed?

Posted on 2010-08-23
6
967 Views
Last Modified: 2013-11-19
Error is "XML Parsing Error: not well-formed" if its utf-8 encoding is choosen

Is der any other character like this which cause problems since i dont have control , whether am retriving all suitable character which doesnt harm the tag since my db holds even Word document content which has numerous symbols.
Why other encoding like utf-8 exists how can i choose encoding which works for all .

Yes, ISO-8859-1 which doesnot causes this error , so is it the best one for encoding someway am not able to understand encoding stuff ?

Note : Xml files are created using ASP Files from db . which is not a issue .

i want to know ,
how to handle this ?
what are the illegal character which doesnot support xml ? Like SQL apostrophe Causes error similarly is der anything in XML which shld be handled?
which encoding is the best that suit all ?

Am curious to know kinda bugs in  xml ?



ASP Code
<%
'I copied pasted the charcter which caused that error ??
Response.write("Character Making Issues How to handle these — "&" This is not minus symbol something else")
%>

Open in new window

samplexml.html
0
Comment
Question by:Rajar Ahmed
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 3

Expert Comment

by:inxni
ID: 33499332
If you have to handle all kind of characters, I would suggest using utf-8 encoding.

But in your case, I think the problem is how to create xml or the data itself because you first hyphen and second hyphen are different characters (Different Code that is)

Can you give more information on how you create xml and when did the error occur?
0
 
LVL 28

Expert Comment

by:sybe
ID: 33499339
> Xml files are created using ASP Files from db . which is not a issue .

The question is *how* you create the xml from db. If you create pseudo-xml, by creating a string, you are very easily making errors.

The best is to use an XML-object to create XML. Or if your database supports it, use a "FOR XML" query.
0
 
LVL 18

Author Comment

by:Rajar Ahmed
ID: 33518803
hi inxni & sybe ,
 
   My apologies for delay in my response, this is my function which does the xml part for me .



<%
Function xml(query)
	Set rs = con.Execute(query)
	Recordcnt = rs.RecordCount
	if Recordcnt > 0 then
		Do While Not Rs.Eof
			xml_str = xml_str & "<heydon>" &vbcrlf _
				 & "<test2><![CDATA["&rs(0)&"]]></test2>" &vbcrlf _
				  & "<test><![CDATA["&rs(1)&"]]></test>" &vbcrlf _
				  & "</heydon>"
		RS.MoveNext
	Loop
   end if
        xml_str = "<?xml version=""1.0"" encoding=""utf-8""?><Homelin>"&xml_str&"</Homelin>"
		set fs=Server.CreateObject("Scripting.FileSystemObject")
        filepath = Server.MapPath("test.xml")
		set fname=fs.CreateTextFile(filepath,true)
		fname.WriteLine(xml_str)
		fname.Close
		set fname=nothing
		set fs=nothing
end function   
%>

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 28

Expert Comment

by:sybe
ID: 33518944
So you create pseudo-xml by creating a string. It's better to use MS XML objects.
0
 
LVL 18

Author Comment

by:Rajar Ahmed
ID: 33519164
does any samples are there . ?

wat will be difference from this ?
0
 
LVL 28

Accepted Solution

by:
sybe earned 500 total points
ID: 33519275
Set oXML = Server.CreateObject("MSXML2.DomDocument.6.0")
oXML.async = False: oXML.resolveExternals = False
Set oRoot = oXML.createElement("root")
oXML.appendChild oRoot

Do While Not Rs.Eof
    Set oNode = oXML.createElement("heydon")
    Set oSubNode = oXML.createElement("test")
    oSubNode.text = rs(0)
    oNode.AppendChild(oSubNode)
    Set oSubNode = oXML.createElement("test")
    oSubNode.text = rs(1)
    oNode.AppendChild(oSubNode)
    oRoot.AppendChild(oNode)

    oRS.MoveNext
Loop


0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question