Web Analytics Made Easy -
StatCounter xml help please - CodingForum

Announcement

Collapse
No announcement yet.

xml help please

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • xml help please

    I have an xml file that is uploaded to the database but if theres( & ) in there it wont upload and I get this error "parser error : Extra content at the end of the document"

    Code:
    <catalog>
    <product>
    <curl>www.company.com</curl>
    <title>test & testing</title>
    <description>testing & test</description>
    </product>
    </catalog>
    Thanks for your help

  • #2
    Originally posted by stebbi View Post
    I have an xml file that is uploaded to the database but if theres( & ) in there it wont upload and I get this error "parser error : Extra content at the end of the document"

    Code:
    <catalog>
    <product>
    <curl>www.company.com</curl>
    <title>test & testing</title>
    <description>testing & test</description>
    </product>
    </catalog>
    Thanks for your help
    replace & with &amp;

    a better solution but bloated in your case:
    Code:
    <description>[ICODE]<![CDATA[[/ICODE]testing & test[ICODE]]]>[/ICODE]</description>
    best regards

    Comment


    • #3
      Thanks I need it to be in the code there will be clients uploading the file cant be sure they will use &amp; can I expect this problem with any other characters?

      Comment


      • #4
        Originally posted by stebbi View Post
        Thanks I need it to be in the code there will be clients uploading the file cant be sure they will use &amp; can I expect this problem with any other characters?
        yes, any character which is not allowed in xml must be replace by it's entity, that means:
        Code:
        & -> &amp;
        < -> &lt;
        > -> &gt;
        ' -> &apos;
        " -> &quot;
        The alternative is to use CDATA sections. If the user upload the file I suggest to use a schema to validate it when they upload.

        My apologize that I didn't explay why in my previos replay.

        best regards

        Comment


        • #5
          It's worth mentioning that the entities (as they're called) in oesyxl's post also work with HTML.
          "The first step to confirming there is a bug in someone else's work is confirming there are no bugs in your own."
          June 30, 2001
          author, ES-Membrane project (Github Pages site)
          author, Verbosio prototype XML Editor
          author, JavaScript Developer's Dictionary
          https://alexvincent.us/blog

          Comment

          Working...
          X