简体   繁体   中英

How to preserve rich text in database?

I am creating a screen in which on the first screen the data stored in the local db will be displayed.On 2nd screen user can edit that data and can also paste rich text.I am using contenteditable div . And for the 3rd screen the user edited data will be displayed and will be stored in db. I am using Java to retrieve and store the data in db. Currently I am facing 2 issue, 1.I am able to paste rich text in my XSL on 2nd screen but it doesn't retain on the third screen and everything becomes like a plain text. 2. I am not sure how to store rich text in db and also retrieve in the same format. I am attaching my XSL sample here. Please let me know if you need any other information.Thanks in advance!

XSL 2nd Screen

<table border="0" cellspacing="1" cellpadding="1" class="graphtable">
    <tr>
        <xsl:choose>
            <xsl:when test="//faml/response/stresponsedto/security_tips">
                <xsl:for-each select="//faml/response/stresponsedto/security_tips/stdto">
                    <td>
                        <div class="carousel" contenteditable="true" id="post-text">
                            <xsl:value-of select="securitytips"/>
                        </div>
                    </td>
                </xsl:for-each>
            </xsl:when>
            <xsl:otherwise></xsl:otherwise>
        </xsl:choose>
    </tr>
    </table> 

XSL 3rd Screen

<table border="0" cellspacing="1" cellpadding="1" class="graphtable">
    <tr>
        <td class="headingalign" width="10%" >Security Tips</td>
    </tr>
    <tr>
        <td style="padding-right: 10px">
            <div class="carousel">
                <xsl:value-of select="//faml/request/fldsandt"/>
            </div>
        </td>
    </tr>
</table>

You may be able to achieve this if you save your 'rich text' as xhtml formatted content. xhtml is html that is also well formed xhtml.

If your content was

<securitytips>
<p>some text with a <b>bold section</b> in it.</p>
</securitytips>

value-of output, like this in XSL

<xsl:value-of select="securitytips" />

will give you just the text :

some text with a bold section in it.

But if you use copy-of you will get the whole element, with markup retained, ie:

<xsl:copy-of select="securitytips" />

will give you text and markup

<p>some text with a <b>bold section</b> in it.</p>

This can get tricky, because if your html is not well formed (eg a tag is not closed), then you won't be able to transform it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM