小编Cod*_*gMo的帖子

如何在创建`Nokogiri :: XML`或`Nokogiri :: HTML`对象时避免创建非重要的空白文本节点

在解析缩进的XML时,从闭合和开始标记之间的空白区域创建非重要的空白文本节点.例如,从以下XML:

<note>
  <to>Tove</to>
  <from>Jani</from>
  <heading>Reminder</heading>
  <body>Don't forget me this weekend!</body>
</note>
Run Code Online (Sandbox Code Playgroud)

其字符串表示如下,

 "<note>\n  <to>Tove</to>\n  <from>Jani</from>\n  <heading>Reminder</heading>\n  <body>Don't forget me this weekend!</body>\n</note>\n"
Run Code Online (Sandbox Code Playgroud)

Document创建以下内容:

#(Document:0x3fc07e4540d8 {
  name = "document",
  children = [
    #(Element:0x3fc07ec8629c {
      name = "note",
      children = [
        #(Text "\n  "),
        #(Element:0x3fc07ec8089c {
          name = "to",
          children = [ #(Text "Tove")]
          }),
        #(Text "\n  "),
        #(Element:0x3fc07e8d8064 {
          name = "from",
          children = [ #(Text "Jani")]
          }),
        #(Text "\n  "),
        #(Element:0x3fc07e8d588c {
          name = "heading",
          children = [ …
Run Code Online (Sandbox Code Playgroud)

html-parsing nokogiri xml-parsing

11
推荐指数
1
解决办法
6284
查看次数

标签 统计

html-parsing ×1

nokogiri ×1

xml-parsing ×1