¿Cómo manejar ' en XML con nokogiri?

I am generating a XML file with the following the key/values using nokogiri XML builder.

<customize>
  <key>[@email=&apos;enter_your_email&apos;]</key>
  <string>foo@gmail.com</string>
</customize>

1.When viewing the generated XML file in browser, it doesn't show &apos; as ' in browser, it just shows as <key>[@email=&apos;enter_your_email&apos;]</key>

2.when viewing generated the XML file as text, it shows

<key>[@email=&amp;apos;enter_your_email&amp;apos;]</key>

Is there any way to remove the amp; when generating XML file? Help me to solve this.

    build = Nokogiri::XML::Builder.new do |xml|
      xml.customize {
          xml.key{ |x| x.text "[@email=&apos;enter_your_email&apos;]"}
          xml.string{ |x| x.text "foo@gmail.com"} 
          }
    end
    build.to_xml

preguntado el 27 de noviembre de 13 a las 05:11

1 Respuestas

I am not quite sure if this helps.

require 'nokogiri'

doc = Nokogiri::XML::Document.new
doc.encoding = 'UTF-8'

puts doc.fragment("<customize>
   <key>[@email=&apos;enter_your_email&apos;]</key>
   <string>foo@gmail.com</string>
 </customize>")

 #=> <customize>
  <key>[@email='enter_your_email']</key>
  <string>foo@gmail.com</string>
</customize>

respondido 27 nov., 13:06

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.