SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Ampersand Confusion: "cannot generate system identifier for general entity"

    I realise that I am meant to specify the ampersand as & and I have done exaclty that but it still comes up this the error.

    I am specifying a list of links in XML and this is one of the links which the error report refers to:

    Code XML:
    <article name="Article 1" url="http://www.example.com?id=4&amp;p=4" color="green"/>

    Anyway, as you can see, in the XML it is specified as &amp; yet when I run the W3c validation check it still brings up the error.

    When I look at the source code for the actual PHP page (which reads and displays the articles from the XML) it does not show &amp; - instead it shows the actual symbol...

    Something must be happening with the parsing of the XML...

    Anyway - Does anyone know how to fix this issue so that it does not throw up an error???

    Thank you
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)

  2. #2
    In memoriam gold trophysilver trophybronze trophy Dan Schulz's Avatar
    Join Date
    May 2006
    Location
    Aurora, Illinois
    Posts
    15,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You probably need to use a numerical entity reference here. I think it's &#38;#38; but I could be wrong.

  3. #3
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,191
    Mentioned
    191 Post(s)
    Tagged
    2 Thread(s)

    spaces

    "Article [space] 1" is not a valid value.

  4. #4
    In memoriam gold trophysilver trophybronze trophy Dan Schulz's Avatar
    Join Date
    May 2006
    Location
    Aurora, Illinois
    Posts
    15,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    *curses silently* How did I miss that?

    *hangs head up in shame*

  5. #5
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mittineague View Post
    "Article [space] 1" is not a valid value.
    How do you know that? Have you seen the DTD or XML Schema for this document? If the name attribute is defined as NAME or ID there are restrictions, but if it's defined as CDATA the attribute value can contain any valid character.

    The &amp; character entity is predefined in both HTML and XML, so it should always be safe to use. Using an NCR (&#38;#38;) as Dan suggests is also valid, but shouldn't be necessary.
    Birnam wood is come to Dunsinane

  6. #6
    In memoriam gold trophysilver trophybronze trophy Dan Schulz's Avatar
    Join Date
    May 2006
    Location
    Aurora, Illinois
    Posts
    15,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Tommy, vBulletin parses NCRs here, so you'll have to type it out as &#38;#38; as I did, but with the #38; part being duplicated.

  7. #7
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know, and I did. But then I edited the message and stupid vBulletin changed it back.
    Birnam wood is come to Dunsinane

  8. #8
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for all your help...

    Dan, I have tried that NCR - the problem persists though.

    Also, the name attribute has been declared as CDATA - sorry that I did not mention that

    Anyway - I have solved the problem - although I have done in a really messy adhoc way.

    I just replaced all instances of & with my own made up character replacement - I used [AMP]

    Then - In the PHP which parses the XML I used str_replace on the URL attribute to replace all instances of [AMP] with &amp;

    Code PHP:
    $attribs['url'] = str_replace('[AMP]','&amp;',$attribs['url']); // <-- Replaces [AMP] with &amp;

    It's so odd that I have to do this for it to work!
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)

  9. #9
    In memoriam gold trophysilver trophybronze trophy Dan Schulz's Avatar
    Join Date
    May 2006
    Location
    Aurora, Illinois
    Posts
    15,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AutisticCuckoo View Post
    I know, and I did. But then I edited the message and stupid vBulletin changed it back.
    You have to type it like this: &#38;#38;#38; if you don't want it to get parsed.

  10. #10
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know. That's what I did. But then I edited the post, which means vBulletin changes it to &#38;#38; in the textarea and when I saved that was interpreted.

    I simply forgot to redo the escape when I edited the post. If you look at the post now, you'll see that it's okay again (since I re-edited).
    Birnam wood is come to Dunsinane

  11. #11
    In memoriam gold trophysilver trophybronze trophy Dan Schulz's Avatar
    Join Date
    May 2006
    Location
    Aurora, Illinois
    Posts
    15,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, at least everyone else who reads this thread will know what to do from now on!

  12. #12
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,191
    Mentioned
    191 Post(s)
    Tagged
    2 Thread(s)

    ampersand

    I wonder if something like what vBulletin does during parsing is also happening with the XML parser (something like needing to escape twice for a double pass?). If so, using &#38;#38;#38; instead of the [AMP] replacement might work.

  13. #13
    bronze trophy
    Join Date
    Dec 2004
    Location
    Sweden
    Posts
    2,670
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mittineague View Post
    I wonder if something like what vBulletin does during parsing is also happening with the XML parser (something like needing to escape twice for a double pass?).
    No... (Unless you're dealing with entity references.)
    Simon Pieters


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •