XML syntax error due to problem characters

Discussion in 'XML & RSS' started by egdcltd, Jun 8, 2007.

  1. #1
    I am adding an rss feed to my site, and am running into an XML parsing error: Syntax error

    This is because occasionally some of the descriptions are using characters that cause problems; in this case %

    How do I correct this please?
     
    egdcltd, Jun 8, 2007 IP
  2. ajsa52

    ajsa52 Well-Known Member

    Messages:
    3,426
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    160
    #2
    The solution depends on, how are you making your xml files ?
    - Manually,
    - Through web services provided by other sites
    - With a program made for you (php, perl, ...)
    - Any commercial application
    - ...
     
    ajsa52, Jun 14, 2007 IP
  3. egdcltd

    egdcltd Peon

    Messages:
    691
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #3
    The feed is a simple php file that calls information from the database.
     
    egdcltd, Jun 15, 2007 IP
  4. ajsa52

    ajsa52 Well-Known Member

    Messages:
    3,426
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    160
    #4
    To avoid that parser error you can enclose your description into CDATA, but the parser must understand that format. Look here for more info: http://www.rssgeneral.com/cdata.html
     
    ajsa52, Jun 15, 2007 IP
  5. Midano

    Midano Peon

    Messages:
    88
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Exactly. CDATA will escape all character-related issues.
     
    Midano, Jun 15, 2007 IP
  6. egdcltd

    egdcltd Peon

    Messages:
    691
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I tried using CDATA, but it completely blanked out all the feed data from the page.
     
    egdcltd, Jun 15, 2007 IP
  7. Midano

    Midano Peon

    Messages:
    88
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I need to see your XML in order to figure out what the problem is.
    Post the feed URL here or PM me.
     
    Midano, Jun 15, 2007 IP
  8. ajsa52

    ajsa52 Well-Known Member

    Messages:
    3,426
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    160
    #8
    So you need to implement a "preparser" function on you PHP side to transform all not XML characters. Example: transform "&" to "&" and so on.
     
    ajsa52, Jun 15, 2007 IP
  9. egdcltd

    egdcltd Peon

    Messages:
    691
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #9
    egdcltd, Jun 15, 2007 IP
  10. MartiCode

    MartiCode Peon

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    You mean, something like htmlspecialchars() that already exists in PHP ? :p
     
    MartiCode, Jun 17, 2007 IP