当前位置: 首页 > news >正文

xml元素值需要保留space

XmlReaderSettings.IgnoreWhitespace 属性

如果忽略空白,则为 true;否则为 false。 默认值为 false。

示例

下面创建一个设置对象,该对象可用于构造一个读取器,该读取器去除处理指令、注释和微不足道的空白。

    StreamReader textreader = new StreamReader(filterXML);XmlReader reader = default(XmlReader);reader = XmlReader.Create(textreader, new XmlReaderSettings{CloseInput = true,ConformanceLevel = ConformanceLevel.Document,DtdProcessing = DtdProcessing.Ignore,IgnoreComments = true,IgnoreProcessingInstructions = false,IgnoreWhitespace = true,ValidationType = ValidationType.None});

注解

不被视为重要的空格包括空格、制表符和空白行,用于设置标记,以便提高可读性。 其中一个示例是元素内容中的空白。
此属性设置不会影响混合内容模式下标记之间的空白,也不会影响在属性范围内 xml:space=‘preserve’ 发生的空白。

<idPkg:Story xmlns:idPkg="http://ns.adobe.com/AdobeInDesign/idml/1.0/packaging" DOMVersion="17.0"><Story Self="u236" AppliedTOCStyle="n" UserText="true" IsEndnoteStory="false" TrackChanges="false" StoryTitle="$ID/" AppliedNamedGrid="n"><StoryPreference OpticalMarginAlignment="false" OpticalMarginSize="12" FrameType="TextFrameType" StoryOrientation="Horizontal" StoryDirection="LeftToRightDirection" /><InCopyExportOption IncludeGraphicProxies="true" IncludeAllResources="false" /><ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/10 Notes Text"><CharacterStyleRange AppliedCharacterStyle="CharacterStyle/$ID/[No character style]"><Properties><Leading type="unit">13.5</Leading><AppliedFont type="object">CompositeFont/~MHeHK-B+TimLTS-B</AppliedFont></Properties><Content> </Content></CharacterStyleRange></ParagraphStyleRange></Story>
</idPkg:Story>
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
exclude-result-prefixes="msxsl"  xmlns:space="http://ns.adobe.com/AdobeInDesign/idml/1.0/packaging"><xsl:output method="xml" indent="yes"/><!-- This is an identity template - it copies everythingthat doesn't match another template --><xsl:template match="@* | node()"><xsl:copy><xsl:apply-templates select="@* | node()"/></xsl:copy></xsl:template><!-- This is the "other template". It says to use your BBB-DDD elementsinstead of the AAA element --><xsl:template match="Content[text()=' ']"><xsl:element name="Content"><xsl:attribute name="xml:space">preserve</xsl:attribute><xsl:value-of select="."></xsl:value-of></xsl:element></xsl:template>
</xsl:stylesheet>

将上面的xml通过xsl转化成带有xml:space=‘preserve’ 的空值元素,新的xml

<Content xml:space="preserve"> </Content>
private string TransformXml(string xmlPath)
{string transformedXmlPath = System.IO.Path.GetTempFileName();XslCompiledTransform xslt = new XslCompiledTransform();string xsltFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "filterSpaceXslt.xslt");xslt.Load(xsltFilePath);xslt.Transform(xmlPath, transformedXmlPath);return transformedXmlPath;
}
http://www.lryc.cn/news/169858.html

相关文章:

  • Eclipse开源代码下载
  • python多线程、进程
  • Vue基础之模板语法介绍
  • 【SLAM】 前端-视觉里程计之特征点
  • Android笔记(二十九):利用python自动生成多语言
  • 【C++STL基础入门】list的运算符重载和关于list的算法
  • 查找内轮廓(孔洞)
  • Git(6)——GitHub
  • 【RocketMQ专题】快速实战及集群架构原理详解
  • [设计模式] 浅谈SOLID设计原则
  • 基于Java+SpringBoot+Vue的旧物置换网站设计和实现
  • Java基本语法2
  • 【数据结构】树的存储结构;树的遍历;哈夫曼树;并查集
  • CSS选择器练习小游戏
  • Python运算符、函数与模块和程序控制结构
  • 微服务保护-Sentinel
  • Doris 导出表结构或数据
  • SELECT * from t_user where user_id = xxx,可以从那几个点去优化这句sql
  • 解决报错 java.lang.IllegalArgumentException: Cannot format given Object as a Date
  • 【Git】03-GitHub
  • Java手写最短路径算法和案例拓展
  • 深度学习实战51-基于Stable Diffusion模型的图像生成原理详解与项目实战
  • 基于matlab实现的多普勒脉冲雷达回波仿真
  • Linux服务器中安装Anaconda+Tensorflow+Keras
  • ubuntu+.net6+docker 应用部署教程
  • Spring常见面试题总结
  • Git全套命令使用
  • 【陕西理工大学-数学软件实训】数学实验报告(8)(数值微积分与方程数值求解)
  • Vue3为什么推荐使用ref而不是reactive
  • JavaScript函数this指向