Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

trouble parsing "&" from xml file

 
swapna Kadali
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you post the part of your XML where the ampersand character is found?
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or you could just make the XML file wellformed.
 
swapna Kadali
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep. The XML is not valid. Your choices are basically A) fixing the XML by encoding "&" as "&amp;", or B) running the XML through a custom "encoder" which replaces occurrences of "&" with "&amp;".
 
swapna Kadali
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks !
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic