Can nokogiri use single quotes for attributes on saving xml?

前端 未结 1 1051
萌比男神i
萌比男神i 2021-01-21 17:38

Nokogiri saves XML attributes with double quotes, even if DOM it read had single quotes. This is totally legitimate of course, but it introduces annoying changes to file content

相关标签:
1条回答
  • 2021-01-21 18:18

    It looks like the answer is no; not as the library is currently written, and maybe not at all. Tracing the call path for a node's serialization:

    • Nokogiri::XML::Node#to_s calls to_xml
    • Nokogiri::XML::Node#to_xml calls serialize (sets a few default options)
    • Nokogiri::XML::Node#serialize calls write_to
    • Nokogiri::XML::Node#write_to calls native_write_to
    • Nokogiri::XML::Node#native_write_to calls native_write_to, which looks like this:

    &bsp;

    def native_write_to(io, encoding, indent_string, options)
      set_xml_indent_tree_output 1
      set_xml_tree_indent_string indent_string
      savectx = LibXML.xmlSaveToIO(IoCallbacks.writer(io), nil, nil, encoding, options)
      LibXML.xmlSaveTree(savectx, cstruct)
      LibXML.xmlSaveClose(savectx)
      io
    end
    

    So, you are at the mercy of libxml at this point. Googling for libxml serialize single quote attributes does not immediately turn up any smoking guns.

    I think you should file a feature request and see what sort of tenderlovin' you can get. :)

    0 讨论(0)
提交回复
热议问题