Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Aug 2008
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    AJAX - Pass in HTML Tags

    I am trying to create an AJAX website. The content that will be updated is text description of the product. I am wondering how would I be able to add HTML tags within the content of my XML?

    For example, ProductA.XML:
    Code:
    <product>
    	<description>This product was inspired by <a href="jason.html">Jason</a></description>
    </product>
    To be clear, I am using AJAX to retrieve XML documents. The XML will be formatted via XSL. Is this the correct format?

  • #2
    Gütkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    You're probably looking for CDATA: http://en.wikipedia.org/wiki/CDATA
    .My new Javascript tutorial site: http://reallifejs.com/
    .Latest article: Calculators — Tiny jQuery calculator, Full-fledged OOP calculator, Big number calculator
    .Latest quick-bit: Including jQuery — Environment-aware minification and CDNs with local fallback

  • #3
    New Coder
    Join Date
    Aug 2008
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I have tried the following with CData but I have had no luck. Am I doing something wrong?

    Code:
    <description> <![CDATA[ Product A is inspired by <a href="http://www.google.ca/">Google</a>. ]]> </description>
    
    <![CDATA[  <description>  Product C is inspired by <a href="http://www.google.ca/">Google</a>. </description> ]]>
    I have uploaded a sample of my project here:
    http://www.sfu.ca/~jca41/stuph/tst/template.html
    http://www.sfu.ca/~jca41/stuph/tst/

  • #4
    Gütkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    Quote Originally Posted by icu222much View Post
    I have tried the following with CData but I have had no luck. Am I doing something wrong?

    Code:
    <description> <![CDATA[ Product A is inspired by <a href="http://www.google.ca/">Google</a>. ]]> </description>
    
    <![CDATA[  <description>  Product C is inspired by <a href="http://www.google.ca/">Google</a>. </description> ]]>
    The first one is definitely the right one.

    You have to make sure that the XSLT processor doesn't escape your HTML:
    Code:
    <xsl:value-of select="content/description" disable-output-escaping="yes" />
    .My new Javascript tutorial site: http://reallifejs.com/
    .Latest article: Calculators — Tiny jQuery calculator, Full-fledged OOP calculator, Big number calculator
    .Latest quick-bit: Including jQuery — Environment-aware minification and CDNs with local fallback

  • #5
    New Coder
    Join Date
    Aug 2008
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I have disable character escaping in the XSL file, but the problem still persists. I have uploaded an updated copy of the file onto http://www.sfu.ca/~jca41/stuph/tst/template.html

    Code:
    <xsl:value-of select="content/description" disable-output-escaping="yes" />

  • #6
    Gütkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    Quote Originally Posted by icu222much View Post
    I have disable character escaping in the XSL file, but the problem still persists
    It seems Firefox does not (and will never) support disable-output-escaping (all the other browsers do).

    Alright, the other way to do this is to get rid of the CDATA and use
    Code:
    <xsl:copy-of select="content/description" />
    You will have to make absolutely sure, though, that the HTML you're putting into your XML is valid XHTML.

    Also, I don't know where this is going, but if it's really just about getting a piece of HTML back to the browser, you might be better off actually serving it as HTML without the XML-wrapper.
    .My new Javascript tutorial site: http://reallifejs.com/
    .Latest article: Calculators — Tiny jQuery calculator, Full-fledged OOP calculator, Big number calculator
    .Latest quick-bit: Including jQuery — Environment-aware minification and CDNs with local fallback

  • Users who have thanked venegal for this post:

    icu222much (12-18-2011)

  • #7
    New Coder
    Join Date
    Aug 2008
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I just wanted to be able to get back some HTML.

    Your solution worked beautifully. Thank you


  •  

    Posting Permissions

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