c# - 解析时删除 XML 空格和换行符
问题描述
我正在尝试将 XML 作为字符串,但所有空格都出现在最终结果中,我尝试了 Regex 并从这里得到了很多答案,但我没有成功。这是我的代码。
public class XMLManager
{
private static XmlDocument xmlInfographic;
private static TextAsset infographicXML;
public XMLManager()
{
infographicXML = Resources.Load("XML/Infographic") as TextAsset;
xmlInfographic = new XmlDocument();
xmlInfographic.LoadXml(infographicXML.text);
}
public static string LoadInformation(int index)
{
return xmlInfographic.DocumentElement.SelectSingleNode("/Infographic/Info/Info" + index).InnerText;
}
}
这里是 XML 文件:
<Infographic>
<Info>
<Info0>
• Something_0.
• Something_0.
• Something_0.
• Something_0.
• Something_0.
</Info0>
<Info1>
• Something_1.
• Something_1.
• Something_1.
</Info1>
</Info>
</Infographic>
当前输出类似于:
\r\n
• Someting_1.
• Someting_1.
• Someting_1.
\r\n
我需要的是:
• Someting_1.
• Someting_1.
• Someting_1.
解决方案
上面的答案是正确的,但你可以用更简洁的方式写:
public static string LoadInformation(int index)
{
return Cleanup(xmlInfographic.DocumentElement.SelectSingleNode("/Infographic/Info/Info" + index).InnerText).Replace("\r\n",string.Empty).Replace(" ", string.Empty);
}
推荐阅读
- azure - Azure csi 磁盘 FailedAttachVolume 问题:无法从磁盘 URL 获取磁盘名称
- php - 如何构造此代码段以存储 MySQL 中列“publicationDate”的日期和时间,同时添加要添加的另一列“editedDate”?
- c# - 在 Visual Studio 中使用自定义应用程序根文件夹发布 c# 项目
- r - 如何解释 R 中的 zeroinf 回归系数?
- sql - 编写一个 sql 查询来查找其患者患有最多不同类型疾病的医生
- php - 使用 GET 方法重写 URL htaccess
- c++ - 为什么这个程序打印出与预期相反的结果?
- python-3.x - 但是, import sklearn 仍然给我错误。更多细节如下。我该如何解决这个问题?
- git - 如何恢复已删除的 bitbucket 存储库
- javascript - 如何从数据库中选择一个复选框