【问题标题】:DataSet.GetXml() converts empty table cell to tag with attribute xml:space="preserve" and a space for valueDataSet.GetXml() 将空表格单元格转换为带有属性 xml:space="preserve" 和值的空格的标记
【发布时间】:2011-02-07 16:13:28
【问题描述】:

我在 ASP.NET 4.0 中遇到了 DataSet.GetXml() 的问题:
首先,我用一些表格填充数据集。
然后我在数据集上运行 .GetXml() 方法并返回一些 XML。但是,此方法的输出不是我想要的。

想要的结果是这样的:

<articles>
    <pkid>57456</pkid>
    <articleid>u34dh</articleid>
    <category>geysdfwty</category>
    <changed>1</changed>
    <email>asd@hwsfn.com</email>
    <header1>Gagasdy</header1>
    <intro>yhsghsdfhert ert erty</intro>
    <layout>Ajr66id</layout>
    <sectionid>jefgd</sectionid>
    <sortorder>0</sortorder>
    <passwordprotect>false</passwordprotect>
    <usr_postalcode>3745</usr_postalcode>
    <retailersort>Gadierg</retailersort>
    <enddate>08-06-2050 00:00:00</enddate>
    <startdate>08-03-2008 00:00:00</startdate>
  </articles>
  <articles>
    <pkid>7845</pkid>
    <articleid>jkfgd</articleid>
    <category>Agjkeydfg</category>
    <changed>1</changed>
    <email>rt@jrudfbdn.com</email>
    <header1>GHadfghf</header1>
    <intro>Ahkrdfg ed tiedfh</intro>
    <layout>Ahoynf</layout>
    <sectionid>jkerbc</sectionid>
    <sortorder>0</sortorder>
    <passwordprotect>false</passwordprotect>
    <usr_postalcode>5484</usr_postalcode>
    <retailersort>Ajrtgdfg</retailersort>
    <enddate>08-06-2050 00:00:00</enddate>
    <startdate>08-03-2008 00:00:00</startdate>
  </articles>

实际输出是这样的:

<articles>
    <pkid>57456</pkid>
    <articleid>u34dh</articleid>
    <category>geysdfwty</category>
    <changed>1</changed>
    <email>asd@hwsfn.com</email>
    <factsbox xml:space="preserve"> </factsbox>
    <header1>Gagasdy</header1>
    <intro>yhsghsdfhert ert erty</intro>
    <keywords xml:space="preserve"> </keywords>
    <layout>Ajr66id</layout>
    <pagetext xml:space="preserve"> </pagetext>
    <sectionid>jefgd</sectionid>
    <sortorder>0</sortorder>
    <textbody xml:space="preserve"> </textbody>
    <passwordprotect>false</passwordprotect>
    <usr_postalcode>3745</usr_postalcode>
    <retailersort>Gadierg</retailersort>
    <enddate>08-06-2050 00:00:00</enddate>
    <startdate>08-03-2008 00:00:00</startdate>
  </articles>
  <articles>
    <pkid>7845</pkid>
    <articleid>jkfgd</articleid>
    <category>Agjkeydfg</category>
    <changed>1</changed>
    <email>rt@jrudfbdn.com</email>
    <factsbox xml:space="preserve"> </factsbox>
    <header1>GHadfghf</header1>
    <intro>Ahkrdfg ed tiedfh</intro>
    <keywords xml:space="preserve"> </keywords>
    <layout>Ahoynf</layout>
    <pagetext xml:space="preserve"> </pagetext>
    <sectionid>jkerbc</sectionid>
    <sortorder>0</sortorder>
    <textbody xml:space="preserve"> </textbody>
    <passwordprotect>false</passwordprotect>
    <usr_postalcode>5484</usr_postalcode>
    <retailersort>Ajrtgdfg</retailersort>
    <enddate>08-06-2050 00:00:00</enddate>
    <startdate>08-03-2008 00:00:00</startdate>
  </articles>

简而言之,我还在数据集的表格中获得了空单元格,并且这些单元格的 xml 节点添加了 xml:space="preserve"。
我该如何阻止这种情况发生?我的意思是,如何阻止单元格被包含在内?

在 ASP.NET 1.1 中使用相同的代码并返回所需的输出。这意味着我必须打开/关闭可能是 4.0 中的一些新事物。但是什么?

非常感谢任何帮助。

提前致谢:)

【问题讨论】:

    标签: asp.net xml


    【解决方案1】:

    我从来没有发现如何正确地做到这一点,所以现在我只是应用一个正则表达式来删除任何具有 xml:space="preserve" 属性的空标签:

    Dim reSpaceReplacer As New Regex("<[^ ]+ xml:space=""preserve"">\s+</[^>]+>")
    strOutput = reSpaceReplacer.Replace(strOutput, "")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-06
      • 2018-05-31
      • 1970-01-01
      • 2014-08-15
      • 1970-01-01
      相关资源
      最近更新 更多