Domanda

I have a XML code looking like this:

<description>&lt;div style=&quot;text-align: justify;&quot;&gt;El Casino de Asturias alberga una sala polivalente para cualquier tipo de acto desde conferencias, convenciones o reuniones de trabajo, hasta banquetes y celebraciones. Dispone de programaci&#243;n mensual de conciertos y actividades y de una variada carta de c&#243;cteles.&lt;br/&gt;&lt;br/&gt;&lt;h4&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Descuento del 30% con la tarjeta tur&#237;stica Gij&#243;n Card (S&#243;lo en la entrada al recinto, no incluye espect&#225;culos)&lt;br/&gt;&lt;/span&gt;&lt;/h4&gt;&lt;/div&gt;</description>

i know that it's in spanish but just look at the html code there's some "divs","ul"(obiusly "li" too) in the middle of the XML

well.... when I create a XQuery query on it I put this description in a row of a table like this:

<table id="pubs" border="1">
        { 
        for $dir in doc("/db/Ocio/pubs.xml")//dir
        order by $dir/name
        return
            <tr>
            <td><p>{$dir/description/text()}</p></td>
            </tr>
        }
</table>

the problem is that when I display this on the web the text is EXACTLY the xml text, my browser don't parse the HTML code and show things like "<ul><li>somethins...</li></ul>" and I don't know how to force the browser to parse the html, I googled it, but all solutions give me how to create HTML with Xquery, not to force browser to parse HTML.

È stato utile?

Soluzione

If you have XQuery 3.0 then you can use the new parse-xml() function like this:

    let $doc := 
    <description>&lt;div style=&quot;text-align: justify;&quot;&gt;El Casino de Asturias alberga una sala polivalente para cualquier tipo de acto desde conferencias, convenciones o reuniones de trabajo, hasta banquetes y celebraciones. Dispone de programaci&#243;n mensual de conciertos y actividades y de una variada carta de c&#243;cteles.&lt;br/&gt;&lt;br/&gt;&lt;h4&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Descuento del 30% con la tarjeta tur&#237;stica Gij&#243;n Card (S&#243;lo en la entrada al recinto, no incluye espect&#225;culos)&lt;br/&gt;&lt;/span&gt;&lt;/h4&gt;&lt;/div&gt;</description>

     return
        <table id="pubs" border="1">
            <tr>
            <td><p>{$doc/text()/parse-xml(.)}</p></td>
            </tr>
</table>

When this XQuery is executed, the correct result (markup -- not text) is produced:

<table id="pubs" border="1">
  <tr>
    <td>
      <p>
        <div style="text-align: justify;">El Casino de Asturias alberga una sala polivalente para cualquier tipo de acto desde conferencias, convenciones o reuniones de trabajo, hasta banquetes y celebraciones. Dispone de programación mensual de conciertos y actividades y de una variada carta de cócteles.<br/>
          <br/>
          <h4>
            <span style="font-weight: bold;">Descuento del 30% con la tarjeta turística Gijón Card (Sólo en la entrada al recinto, no incluye espectáculos)<br/>
            </span>
          </h4>
        </div>
      </p>
    </td>
  </tr>
</table>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top