| Author |
trouble parsing "&" from xml file
|
swapna Kadali
Greenhorn
Joined: Oct 06, 2003
Posts: 22
|
|
Hi, I have data which has "&" operator in my xml file. When I was trying to populate data from xml file into a dropdownlistbox, I have an error : "Error occured while parsing Entity Name from xml file" Did anybody had this problem, If so how did you solve that? Ofcourse I am doing this in ASP.NET web application, but I think parsing xml file is same in any language. Thanks, Swapna
|
 |
Lasse Koskela
author
Sheriff
Joined: Jan 23, 2002
Posts: 11962
|
|
|
Could you post the part of your XML where the ampersand character is found?
|
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
|
|
When you are storing the information it is best to run a piece of code that changes " and & to the escaped state. That is what i do and I program in .NET, but it is the same all around. The error comes when the complier sees the & and expects to do something else with it. Eric
|
 |
Lasse Koskela
author
Sheriff
Joined: Jan 23, 2002
Posts: 11962
|
|
|
Or you could just make the XML file wellformed.
|
 |
swapna Kadali
Greenhorn
Joined: Oct 06, 2003
Posts: 22
|
|
Hi Lasee and Eric, Thanks to both of you for the reply. Eric, Yes you are right, I should handle that error in my code. Lasse, here is my xml file, can u see "&"(MN&O)in the last name element..? right there.......... <?xml version="1.0"?> <root> <xsd:schema id="OrganizationType" targetNamespace="" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> <xsd:element name="OrganizationType"> <xsd:complexType> <xsd:all> <xsd:element name="Name" minOccurs="0" type="xsd:string" /> <xsd:element name="Abbreviation" minOccurs="0" type="xsd:string" /> </xsd:all> </xsd:complexType> </xsd:element> </xsd:schema> <OrganizationTypes> <OrganizationType> <Name>ABC</Name> <Abbreviation>PT</Abbreviation> </OrganizationType> <OrganizationType> <Name>DEF</Name> <Abbreviation>CON</Abbreviation> </OrganizationType> <OrganizationType> <Name>GHI</Name> <Abbreviation>PT</Abbreviation> </OrganizationType> <OrganizationType> <Name>JKL</Name> <Abbreviation>PT</Abbreviation> </OrganizationType> <OrganizationType> <Name>MN&O</Name> <Abbreviation>PT</Abbreviation> </OrganizationType> </OrganizationTypes> </root>
|
 |
Lasse Koskela
author
Sheriff
Joined: Jan 23, 2002
Posts: 11962
|
|
|
Yep. The XML is not valid. Your choices are basically A) fixing the XML by encoding "&" as "&", or B) running the XML through a custom "encoder" which replaces occurrences of "&" with "&".
|
 |
swapna Kadali
Greenhorn
Joined: Oct 06, 2003
Posts: 22
|
|
|
Thanks !
|
 |
 |
|
|
subject: trouble parsing "&" from xml file
|
|
|