Promblem while parsing the XML

Posted on 2006-03-23
Last Modified: 2013-11-19

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.
Question by:hemanexp
    LVL 60

    Expert Comment

    by:Geert Bormans
    you have to replace & by &amp;
    LVL 60

    Accepted Solution

    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;

    LVL 8

    Expert Comment

    by:Leo Eikelman
    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..



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
    Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
    Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    760 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now