Pergunta

Estou trabalhando com a jddom no momento. Não consigo pensar em uma solução que deve ser essencialmente um problema fácil.

Eu tenho uma string xhtml válida:

<b>M&amp;A</b> &euro;

Como faço para inserir isso no XML DOM da seguinte forma?

<parentNode>
  <b>M&amp;A</b>
  €
</parentNode>

(Este XML então vai para um transformador XSL, que depois renderiza o XHTML para o navegador)

Eu criei as seguintes soluções 'pseudo', mas não tenho certeza se elas são possíveis:

Entidades descontiais que não são entidades XML e depois insira.
Somente o XML está atita, depois html desconta a sequência inteira e insira.

Taras

Foi útil?

Solução

I guess you can use JTidy to transform named entities to numbered ones. After that, the XHTML is also valid XML.

Outras dicas

While &euro; is valid XHTML entity it is not valid XML one.

Unfortunately, I don't know anything about JDOM, but if it is possible you may try adding DTD entity declarations like <!ENTITY euro "€">. And, maybe, put all XHTML tags into their proper namespace (<parentNode xmlns:x="http://www.w3.org/1999/xhtml"><x:b>...</x:b></parentNode>)

Create a string containing

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>

+

your XHTML content, in this case <b>M&amp;A</b> &euro;

+

</html>

and then parse this string to obtain a document. Then get all the content inside the root element, that will be your XHTML content and place it inside your parentNode element. You may need to take into account that the content comes from a different document.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top