• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 856
  • Last Modified:

Promblem while parsing the XML

Hi,


I got the follwoing error while parsing the XML file.

[Fatal Error] :2:2325: The entity name must immediately follow the '&' in the entity reference.

 Exception: org.xml.sax.SAXParseException: The entity name must immediately follow the '&' in the entity reference.

My XML has a tag called <company_name> which contains & symbol like "ABC & Co".
How can i resolve it.

Thanx in advance.
0
hemanexp
Asked:
hemanexp
  • 2
1 Solution
 
Geert BormansCommented:
you have to replace & by &amp;
0
 
Geert BormansCommented:
an entity in XML is some sort of a shortcut or escape
you can define an entity eg "&MyComp;" as being "The full name of my Company"
and the parser will replace every instance of "&MyComp;" with "The full name of my Company"

For that, the parser expects an entity every time it hits a "&"

So if you want to use a plain "&" in your text, you need to replace it with a built in entity "&amp;"

There are several special characters in XML that have a prebuilt entity
&amp; = &
&lt; = <
&gt; = >
&apos; = '
&quot; = "

you can also escape special characters like this
&#233; = é (the unicode character 233)

or you can define your own entities
see example &MyComp;

cheers
0
 
Leo EikelmanDirector, IT and Business DevelopmentCommented:
Or enclose the expression with CDATA:

<param name="expression"><![CDATA[ myURL.indexOf('&') > 0 ]]</param>

This might be a better solution as it will catch ANY characters that will cause this problem

such as &, >, <, etc..


Cheers,

Leo
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now