XML Validation error : EntityRef: expecting';'

73,902

Solution 1

Your URL must be escaped.

& character is used in XML to insert a character reference with syntax &name; (note ; after name). Parser expects a ; but it can't find it (there are more available delimiters, this is just most common case).

Solution is then escaping (how it's done depends on language you use to generate that XML file) but final result must be something like this:

<url>
  <loc>http://www.ezed.in/ezed/courseDemoIntroPage.do?courseId=COU10000000138003530&amp;checkingCourseFrom=preLogin#.U2DcKvmSySo</loc>
</url>

Note that plain & has been replaced with its escaped version &amp;. For further details see this simple article.

Another possible solution (if you don't want/you can't escape) is to enclose URL inside a CDATA section like this:

<url>
  <loc><![CDATA[http://www.ezed.in/ezed/courseDemoIntroPage.do?courseId=COU10000000138003530&checkingCourseFrom=preLogin#.U2DcKvmSySo]]></loc>
</url>

Solution 2

Another way as below:

Instead of "CDATA" we could use htmlspecialchars PHP native function for url node. it will work few of xml feed they don't want CDATA in xml output so this will be helpful for someone.

Thanks

Solution 3

I stumbled on the same problem today, if you are building the links with PHP you can use this function:

htmlspecialchars();

It will format the desired string for you to HTML chars so you can insert it as a <loc>.

Share:
73,902

Related videos on Youtube

ousepachn
Author by

ousepachn

Updated on February 09, 2021

Comments

  • ousepachn
    ousepachn over 3 years
    <url>
      <loc>http://www.ezed.in/ezed/courseDemoIntroPage.do?courseId=COU10000000138003530&checkingCourseFrom=preLogin#.U2DcKvmSySo</loc>
    </url>
    

    error on line 102 at column 103: EntityRef: expecting';'

    Not able to figure out what could be the problem.

  • stamster
    stamster almost 7 years
    If parser cannot parse it - how you're suppose to run any function on nodes? You cannot iterate over XML object at all when there's a parser error.
  • barbsan
    barbsan almost 5 years
    Isn't it the same advice as in this answer?
  • Lambert
    Lambert over 4 years
    For me the CDATA did not works. But replace &amp; works very well for the super long URL.
  • titoih
    titoih about 4 years
    it works, thank you very much! just one questio: why is it working without scaping in localhost, but it isn't in production?
  • Adriano Repetti
    Adriano Repetti about 4 years
    There shouldn't be any difference unless the url or error handling are different