我在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中的新功能。但是什么?
非常感谢任何帮助。
提前致谢:)
答案 0 :(得分:0)
我从未发现如何正确地执行此操作,因此现在我只应用RegEx删除任何具有xml:space =“preserve”属性的空标记:
Dim reSpaceReplacer As New Regex("<[^ ]+ xml:space=""preserve"">\s+</[^>]+>")
strOutput = reSpaceReplacer.Replace(strOutput, "")