Solved

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

Posted on 2010-08-23
6
965 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
Independent Software Vendors: 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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Validating Date 4 38
How to build a web site 17 102
Record locking on classic ASP 3 64
How to properly export data from two SAS datasets to one XML data file? 5 46
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…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
The viewer will learn how to count occurrences of each item in an array.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

739 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