Solved

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

Posted on 2010-08-23
6
954 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
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. 
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
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…

760 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

21 Experts available now in Live!

Get 1:1 Help Now