3

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.

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Santanor
  • 566
  • 1
  • 7
  • 20
  • I haven't worked with xQuery before, so i don't have a proper answer, but I think that you have to unescape the html entities in the string, this question may help http://stackoverflow.com/questions/2611480/how-to-unencode-escaped-xml-with-xquery – Roimer Dec 29 '12 at 15:48

1 Answers1

4

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>
Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431
  • Thank you so much dude, i'm going to try it right now, thank you again :D – Santanor Dec 29 '12 at 19:20
  • i'm sorry to ask again, but when i use this function the webapp return me this error: Function parse-xml() is not defined in module namespace: http://www.w3.org/2005/xpath-functions i googled about it but i cannot find a namespace with that function i put the Zorba's namespace but returns 404 the url, u know the solution? Tnak you very much – Santanor Dec 30 '12 at 14:44
  • @Santanor, As I have clearly said in this answer, `parse-xml()` is a standard XPath 3.0 function and is available in any XQuery 3.0 implementation. I run the above code successfully, both with Saxon 9.3.04EE and with XBase 7.5. The `parse-xml()` function is defined here: http://www.w3.org/TR/xpath-functions-30/#func-parse-xml – Dimitre Novatchev Dec 30 '12 at 16:06