Solved

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

Posted on 2010-08-23
6
963 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
  • 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

749 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