Solved

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

Posted on 2010-08-23
6
961 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Transform XML to Excel using XSL 1 30
XML to Excel using XSL - formatting 3 32
Error in query expression 3 42
Query still returning duplicates 5 26
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
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…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

816 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now