C# Xmlexception An Error Occurred While Parsing Entityname
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site system xml xmlexception an error occurred while parsing entityname About Us Learn more about Stack Overflow the company Business Learn more about an error occurred while parsing entityname ampersand hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join an error occurred while parsing entityname xml document the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up An error occurred while parsing
An Error Occurred While Parsing Entityname Vb Net
EntityName. Line1, position 844 up vote 10 down vote favorite 4 I have got the following exception from the below code block. An error occurred while parsing EntityName. Line1, position 844. I was trying to parse s set of data retrieved from table to a data set. public DataSet BindMasterData(string xml) { DataSet ds = null; try { ds = new DataSet(); TextReader txtReader = an error occurred while parsing entityname line 1 position 48 new StringReader(xml); XmlReader reader = new XmlTextReader(txtReader); ds.ReadXml(reader); } catch (Exception ex) { return new DataSet(); } return ds; } I have figured out the reason for the exception, but I couldn't solve it. In this particular situation, the string(which is retrieved from DB) contains a special character (&). That causes exception. How I can solve it. Any help on this would be great. Thanks & Regards Sebastian c# xml share|improve this question asked May 8 '14 at 12:33 Sebastian Xavier 42231029 1 Please show the part of the document which causes the exception. –Codor May 8 '14 at 12:35 The string contains &. For Ex. A & B Constructions –Sebastian Xavier May 8 '14 at 12:40 add a comment| 4 Answers 4 active oldest votes up vote 19 down vote accepted Just replace them: Not valid in XML elements: " " ' ' < < > > & & public static string UnescapeXMLValue(string xmlString) { if (xmlString == null) throw new ArgumentNullException("xmlString") return xmlString.Replace("'", "'").Replace(""", "\"").Replace(">", ">").Replace("<", "<").Replace("&", "&"); } public static string EscapeXMLValue(string xmlString) { if (xmlString == null) throw new ArgumentNullException("xmlString") return xmlString.Replace("'","'").Replace( "\"", """).Replace(">",">").Replace( "<","<").Replace( "&","&"); } share|
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more an error occurred while parsing entityname nuget about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges
Error Occurred While Parsing Signed Message
Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each
Failed To Invoke Web Service. An Error Occurred While Parsing Entityname
other. Join them; it only takes a minute: Sign up error occurred while parsing EntityName on xml up vote 3 down vote favorite I have found that there exists "&" in my code that's why error is showing http://stackoverflow.com/questions/23541910/an-error-occurred-while-parsing-entityname-line1-position-844 XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(dsExport.Tables[0].Rows[i]["SubmissionData"].ToString()); The "&" is there in submissiondata . How can I remove the special characters so that the error doesn't show again ? Thanks in advance c# xml share|improve this question edited Jul 17 '13 at 14:18 Microsoft DN 5,03332245 asked Jul 17 '13 at 14:16 user2265679 74110 What is the error? –Microsoft DN Jul 17 '13 at 14:18 An error occurred while parsing EntityName. Line 14, position 84. http://stackoverflow.com/questions/17702251/error-occurred-while-parsing-entityname-on-xml Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Xml.XmlException: An error occurred while parsing EntityName. Line 14, position 84. Source Error: Line 45: { Line 46: Line 47: xmlDoc.LoadXml(dsExport.Tables[0].Rows[i]["SubmissionData"].ToString()); –user2265679 Jul 17 '13 at 14:19 i found out that "&" is there is submissiondata. thats why the error is showing –user2265679 Jul 17 '13 at 14:20 @pal thingbo the same problem is occuring for me social.msdn.microsoft.com/Forums/windows/en-US/… –user2265679 Jul 17 '13 at 14:29 add a comment| 4 Answers 4 active oldest votes up vote 3 down vote accepted Replace your "&" with "&" share|improve this answer edited Jul 17 '13 at 14:44 HamZa 11k93067 answered Jul 17 '13 at 14:22 Microsoft DN 5,03332245 but it is taking from the Web service. we are not giving it manually. –user2265679 Jul 17 '13 at 14:23 @MicrosoftDJ please expand your answer, it does not sufficiently explain what's wrong and has been automatically marked by the system as a low quality post as a result. –Esoteric Screen Name Jul 17 '13 at 14:43 add a comment| up vote 0 down vote & is not an illegal XML character. This is not your problem. You need to log the XML that you receive,
Tips/Tricks Top Articles Beginner Articles Technical Blogs Posting/Update Guidelines Article Help Forum Article Competition Submit an article or tip Post your Blog quick answersQ&A Ask a Question View Unanswered Questions http://www.codeproject.com/Questions/770749/An-error-occurred-while-parsing-EntityName-Line-po View All Questions... C# questions Linux questions ASP.NET questions SQL questions VB.NET questions http://forums.asp.net/t/1291485.aspx?+An+error+occurred+while+parsing+EntityName+Line+1+position+3476+while+loading+XML+document discussionsforums All Message Boards... Application Lifecycle> Running a Business Sales / Marketing Collaboration / Beta Testing Work Issues Design and Architecture ASP.NET JavaScript C / C++ / MFC> ATL / WTL / STL Managed C++/CLI C# Free Tools Objective-C and Swift Database Hardware & Devices> System Admin Hosting and Servers Java error occurred .NET Framework Android iOS Mobile SharePoint Silverlight / WPF Visual Basic Web Development Site Bugs / Suggestions Spam and Abuse Watch features Competitions News The Insider Newsletter The Daily Build Newsletter Newsletter archive Surveys Product Showcase Research Library CodeProject Stuff communitylounge Who's Who Most Valuable Professionals The Lounge The Insider News The Weird & The Wonderful The Soapbox Press Releases Non-English Language > error occurred while General Indian Topics General Chinese Topics help What is 'CodeProject'? General FAQ Ask a Question Bugs and Suggestions Article Help Forum Site Map Advertise with us About our Advertising Employment Opportunities About Us Ask a Question All Questions All Unanswered FAQ An error occurred while parsing EntityName. Line1, position 844. Rate this: Please Sign up or sign in to vote. See more: C# XML Hi All, I have got the following exception from the below code block. An error occurred while parsing EntityName. Line1, position 844. I was trying to parse s set of data retrieved from table to a data set. public DataSet BindMasterData(string xml) { DataSet ds = null; try { ds = new DataSet(); TextReader txtReader = new StringReader(xml); XmlReader reader = new XmlTextReader(txtReader); ds.ReadXml(reader); } catch (Exception ex) { return new DataSet(); } return ds; } I have figured out the reason for the exception, but I couldn't solve it. In this particular situation, the string(which is retrieved from DB) contains a special character (&). That causes exception. How I can solve it. Any help on this would be great. Thanks & Regards Sebastian Posted
ASP.NET Community Standup Forums Help Home/ASP.NET Forums/Data Access/XML and XmlDataSource Control/{"An error occurred while parsing EntityName. Line 1, position 3476."... {"An error occurred while parsing EntityName. Line 1, position 3476."} while loading XML document [Answered]RSS 2 replies Last post Jul 22, 2008 05:01 AM by Samu Zhang - MSFT ‹ Previous Thread|Next Thread › Print Share Twitter Facebook Email Shortcuts Active Threads Unanswered Threads Unresolved Threads Support Options Advanced Search Reply sam123456789 Member 1 Points 7 Posts {"An error occurred while parsing EntityName. Line 1, position 3476."} while loading XML document Jul 17, 2008 09:47 AM|sam123456789|LINK Hi, I have an XML document which has an element with an ampersand. I have the ampersand escaped correctly.
Hello world& Test Rd However, when I read this XML as a string then try to do a load on it Xmldocument.Load(xmlstring) i get an exception {"An error occurred while parsing EntityName. Line 1, position 3476."} while loading XML document}. Any ideas what I am doing wrong? Thanks --Sam XML Parsing Reply sam123456789 Member 1 Points 7 Posts Re: {"An error occurred while parsing EntityName. Line 1, position 3476."} while loading XML docu... Jul 17, 2008 11:03 AM|sam123456789|LINK I found the reason, but I dont know how to fix. I am passing the xml document as a request paramter and I am reading it from a file in classic asp then sending it in as a form parameter. It seems that the & gets automatically converted to & and when this gets read by .Net after I forward to the .Net page, I get the error. Any suggestions on how to fix? Thanks --Sam Reply Samu Zhang -... All-Star 51217 Points 6089 Posts Re: {"An error occurred while parsing EntityName. Line 1, position 3476."} while loading XML docu... Jul 22, 2008 05:01 AM|Samu Zhang - MSFT|LINK Hi sam123456789 , I am not familar with classic asp. But you can replace it with "&" string str = "