[prev in list] [next in list] [prev in thread] [next in thread] 

List:       xml-cocoon-users
Subject:    Is there a way to inject tags in a text field from Cocoon 2.1 into MySQL using sql:execute-query?
From:       Philippe Faehndrich <phfaehndrich () bluewin ! ch>
Date:       2017-04-29 23:41:43
Message-ID: 1f736d6d-2e8c-9f7b-a730-7cacf3b77794 () bluewin ! ch
[Download RAW message or body]

Hi everybody,

I'm working since many years with Cocoon 2.1 within a Tomcat server and 
I need now to inject the content of my XML files in a MySQL database.

The problem is I have some XML elements (MySQL columns) that do contain 
HTML tags (some "<br/>", "<i>...</i>" and a few "<a href url="..."/>).

For now, all tags seem simply to be trimmed away from my output.

Is there a way to inject tags in a text field from Cocoon 2.1 into MySQL 
using <sql:execute-query>?

My database connection is defined as following in WEB-INF/cocoon.xconf:

     <jdbc name="dautrepart">
       <pool-controller min="1" max="10"/>
<dburl>jdbc:mysql://localhost:3306/dautrepart</dburl>
       <user>webapp</user>
       <password>webapp</password>
     </jdbc>

In the sitemap, I have these lines:

             <map:match pattern="copier.html">
                 <map:generate type="xpathdirectory" 
src="../bac_a_sable/textes" label="content">
                     <map:parameter name="xpath" value="/fiche"/>
                     <map:parameter name="include" value=".xml"/>
                 </map:generate>
                 <map:transform src="nettoyer_structure.xslt" 
label="debug01"/>
                 <map:transform src="preparer_sql.xslt" label="debug02"/>
                 <map:transform src="injection.xslt" label="requetes"/>
                 <map:transform type="sql">
                     <map:parameter name="use-connection" 
value="dautrepart"/>
                 </map:transform>
                 <map:serialize type="xml"/>
             </map:match>

And concerned parts of my stylesheet appears as follow:

                 <sql:execute-query>
                     <sql:query name="inserer_auteur">
                         <xsl:text>INSERT INTO auteur (nom, prenom, 
identifiant, biographie, portrait_petit) VALUES ("</xsl:text>
                         <xsl:value-of select="identite/nom"/>
                         <xsl:text>", "</xsl:text>
                         <xsl:value-of select="identite/prenom"/>
                         <xsl:text>", "</xsl:text>
                         <xsl:value-of select="identite/@id"/>
                         <xsl:text>", "</xsl:text>
                         <xsl:apply-templates select="bio"/>
                         <xsl:text>", "</xsl:text>
                         <xsl:value-of select="identite/portrait"/>
                         <xsl:text>")</xsl:text>
                     </sql:query>
                 </sql:execute-query>

     <xsl:template match="bio">
         <xsl:apply-templates/>
     </xsl:template>

     <xsl:template match="i">
         <i>
             <xsl:apply-templates/>
         </i>
     </xsl:template>

An extract of the file I have:

<fiche>
<identiteid="boissier_laurence">
<nom>Boissier</nom>
<prenom>Laurence</prenom>
<portrait>boissier_laurence_150x100.png</portrait>
</identite>
<bio>
Née en 1965, elle habite dans le canton de Genève. Participe à Bern ist 
überall et au cd
<i>Renens (VD)</i>
. Prix suisse de littérature 2017 pour
<i>Inventaire des lieux</i>
paru chez art&fiction.
<br/>
</bio>



[Attachment #3 (text/html)]

<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    Hi everybody,<br>
    <br>
    I'm working since many years with Cocoon 2.1 within a Tomcat server
    and I need now to inject the content of my XML files in a MySQL
    database.<br>
    <br>
    The problem is I have some XML elements (MySQL columns) that do
    contain HTML tags (some "&lt;br/&gt;", "&lt;i&gt;...&lt;/i&gt;" and
    a few "&lt;a href url="..."/&gt;).<br>
    <br>
    For now, all tags seem simply to be trimmed away from my output.<br>
    <br>
    Is there a way to inject tags in a text field from Cocoon 2.1 into
    MySQL using &lt;sql:execute-query&gt;?<br>
    <br>
    My database connection is defined as following in
    WEB-INF/cocoon.xconf:<br>
    <br>
        &lt;jdbc name="dautrepart"&gt;<br>
          &lt;pool-controller min="1" max="10"/&gt;<br>
         
    &lt;dburl&gt;jdbc:mysql://localhost:3306/dautrepart&lt;/dburl&gt;<br>
          &lt;user&gt;webapp&lt;/user&gt;<br>
          &lt;password&gt;webapp&lt;/password&gt;<br>
        &lt;/jdbc&gt;<br>
    <br>
    In the sitemap, I have these lines:<br>
    <br>
                &lt;map:match pattern="copier.html"&gt;<br>
                    &lt;map:generate type="xpathdirectory"
    src="../bac_a_sable/textes" label="content"&gt;<br>
                        &lt;map:parameter name="xpath"
    value="/fiche"/&gt;<br>
                        &lt;map:parameter name="include"
    value=".xml"/&gt;<br>
                    &lt;/map:generate&gt;<br>
                    &lt;map:transform src="nettoyer_structure.xslt"
    label="debug01"/&gt;<br>
                    &lt;map:transform src="preparer_sql.xslt"
    label="debug02"/&gt;<br>
                    &lt;map:transform src="injection.xslt"
    label="requetes"/&gt;<br>
                    &lt;map:transform type="sql"&gt;<br>
                        &lt;map:parameter name="use-connection"
    value="dautrepart"/&gt;<br>
                    &lt;/map:transform&gt;<br>
                    &lt;map:serialize type="xml"/&gt;<br>
                &lt;/map:match&gt;<br>
    <br>
    And concerned parts of my stylesheet appears as follow:<br>
    <br>
                    &lt;sql:execute-query&gt;<br>
                        &lt;sql:query name="inserer_auteur"&gt;<br>
                            &lt;xsl:text&gt;INSERT INTO auteur (nom,
    prenom, identifiant, biographie, portrait_petit) VALUES
    ("&lt;/xsl:text&gt;<br>
                            &lt;xsl:value-of select="identite/nom"/&gt;<br>
                            &lt;xsl:text&gt;", "&lt;/xsl:text&gt;<br>
                            &lt;xsl:value-of
    select="identite/prenom"/&gt;<br>
                            &lt;xsl:text&gt;", "&lt;/xsl:text&gt;<br>
                            &lt;xsl:value-of select="identite/@id"/&gt;<br>
                            &lt;xsl:text&gt;", "&lt;/xsl:text&gt;<br>
                            &lt;xsl:apply-templates select="bio"/&gt;<br>
                            &lt;xsl:text&gt;", "&lt;/xsl:text&gt;<br>
                            &lt;xsl:value-of
    select="identite/portrait"/&gt;<br>
                            &lt;xsl:text&gt;")&lt;/xsl:text&gt;<br>
                        &lt;/sql:query&gt;<br>
                    &lt;/sql:execute-query&gt;<br>
    <br>
        &lt;xsl:template match="bio"&gt;<br>
            &lt;xsl:apply-templates/&gt;<br>
        &lt;/xsl:template&gt;<br>
    <br>
        &lt;xsl:template match="i"&gt;<br>
            &lt;i&gt;<br>
                &lt;xsl:apply-templates/&gt;<br>
            &lt;/i&gt;<br>
        &lt;/xsl:template&gt;<br>
    <br>
    An extract of the file I have:<br>
    <br>
    <meta http-equiv="content-type" content="text/html;
      charset=windows-1252">
    <div class="line"><span class="html-tag">&lt;fiche&gt;</span></div>
    <div class="collapsible-content" style="margin-left: 1em;">
      <div class="collapsible" id="collapsible371">
        <div class="expanded">
          <div class="line"><span class="button collapse-button"
              style="user-select: none; cursor: pointer; display:
              inline-block; margin-left: -10px; width: 10px; background:
              url(&quot;data:image/svg+xml,&lt;svg
              xmlns='http://www.w3.org/2000/svg' fill='#909090'
              width='10' height='10'&gt;&lt;path d='M0 0 L8 0 L4 7
              Z'/&gt;&lt;/svg&gt;&quot;); vertical-align: bottom;
              height: 10px;"></span><span class="html-tag">&lt;identite<span
                class="html-attribute"><span
                  class="Apple-converted-space"> </span><span
                  class="html-attribute-name">id</span>="<span
                  class="html-attribute-value">boissier_laurence</span>"</span>&gt;</span></div>
          <div class="collapsible-content" style="margin-left: 1em;"><span
              class="text"></span>
            <div class="line"><span class="html-tag">&lt;nom&gt;</span><span
                class="text">Boissier</span><span class="html-tag">&lt;/nom&gt;</span></div>
            <span class="text"></span>
            <div class="line"><span class="html-tag">&lt;prenom&gt;</span><span
                class="text">Laurence</span><span class="html-tag">&lt;/prenom&gt;</span></div>
            <span class="text"></span>
            <div class="line"><span class="html-tag">&lt;portrait&gt;</span><span
                class="text">boissier_laurence_150x100.png</span><span
                class="html-tag">&lt;/portrait&gt;</span></div>
            <span class="text"></span></div>
          <div class="line"><span class="html-tag">&lt;/identite&gt;</span></div>
        </div>
      </div>
      <div class="collapsible" id="collapsible372">
        <div class="expanded">
          <div class="line"><span class="button collapse-button"
              style="user-select: none; cursor: pointer; display:
              inline-block; margin-left: -10px; width: 10px; background:
              url(&quot;data:image/svg+xml,&lt;svg
              xmlns='http://www.w3.org/2000/svg' fill='#909090'
              width='10' height='10'&gt;&lt;path d='M0 0 L8 0 L4 7
              Z'/&gt;&lt;/svg&gt;&quot;); vertical-align: bottom;
              height: 10px;"></span><span class="html-tag">&lt;bio&gt;</span></div>
          <div class="collapsible-content" style="margin-left: 1em;"><span
              class="text">Née en 1965, elle habite dans le canton de
              Genève. Participe à Bern ist überall et au cd</span>
            <div class="line"><span class="html-tag">&lt;i&gt;</span><span
                class="text">Renens (VD)</span><span class="html-tag">&lt;/i&gt;</span></div>
            <span class="text">. Prix suisse de littérature 2017 pour</span>
            <div class="line"><span class="html-tag">&lt;i&gt;</span><span
                class="text">Inventaire des lieux</span><span
                class="html-tag">&lt;/i&gt;</span></div>
            <span class="text">paru chez art&amp;fiction.</span>
            <div class="line"><span class="html-tag">&lt;br/&gt;</span></div>
            <span class="text"></span></div>
          <div class="line"><span class="html-tag">&lt;/bio&gt;</span></div>
        </div>
      </div>
      <div class="collapsible" id="collapsible373">
        <div class="expanded">
          <div class="line"><span class="button collapse-button"
              style="user-select: none; cursor: pointer; display:
              inline-block; margin-left: -10px; width: 10px; background:
              url(&quot;data:image/svg+xml,&lt;svg
              xmlns='http://www.w3.org/2000/svg' fill='#909090'
              width='10' height='10'&gt;&lt;path d='M0 0 L8 0 L4 7
              Z'/&gt;&lt;/svg&gt;&quot;); vertical-align: bottom;
              height: 10px; color: rgb(0, 0, 0); font-family: monospace;
              font-size: 13px; font-style: normal;
              font-variant-ligatures: normal; font-variant-caps: normal;
              font-weight: normal; letter-spacing: normal; orphans: 2;
              text-align: start; text-indent: 0px; text-transform: none;
              white-space: normal; widows: 2; word-spacing: 0px;
              -webkit-text-stroke-width: 0px; text-decoration-style:
              initial; text-decoration-color: initial;"></span><span
              class="html-tag" style="font-family: monospace; font-size:
              13px; font-style: normal; font-variant-ligatures: normal;
              font-variant-caps: normal; font-weight: normal;
              letter-spacing: normal; orphans: 2; text-align: start;
              text-indent: 0px; text-transform: none; white-space:
              normal; widows: 2; word-spacing: 0px;
              -webkit-text-stroke-width: 0px; text-decoration-style:
              initial; text-decoration-color: initial;"><br
                class="Apple-interchange-newline">
            </span></div>
        </div>
      </div>
    </div>
    <br>
  </body>
</html>


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic