8
votes

Comment obtenez-vous inner_html de Ruby Nokogiri Nodet non évalué?

J'aimerais avoir un déficit html intérieure intérieure non évaluée d'un Nokogiri Nodet. Est-ce que quelqu'un sait comment faire cela?


0 commentaires

4 Réponses :


4
votes

Tout ce qui n'est pas correct avec? XXX


0 commentaires

0
votes

Une ancienne version de LibxML2 pourrait causer Nokogiri de retourner des caractères échappés. J'ai eu ce problème récemment.


0 commentaires

2
votes

Le LOOFAH GEM m'a beaucoup aidé ici.


0 commentaires

1
votes

envelopper vos nœuds dans cdata: xxx pré>

nokogiri :: xml :: nœud # inner_html code> échappe aux entités html sauf dans les sections CDATA. P>

fragment = Nokogiri::HTML.fragment "<div>Here is an unescaped string: <span>Turn left > right > straight & reach your destination.</span></div>"
puts fragment.inner_html
# <div>Here is an unescaped string: <span>Turn left &gt; right &gt; straight &amp; reach your destination.</span></div>


fragment.xpath(".//span").each {|node| node.inner_html = node.document.create_cdata(node.content) }
fragment.inner_html
# <div>Here is an unescaped string: <span>Turn left > right > straight & reach your destination.</span>\n</div>


0 commentaires