是否可以在XML文件中跨多行分割一个字符串?如果可以,如何进行?[英] Is it possible to split a string across multiple lines in an XML file? If so, how?

本文是小编为大家收集整理的关于是否可以在XML文件中跨多行分割一个字符串?如果可以,如何进行?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我有一个非常长的字符串的XML配置文件.通常,我格式化了我的源文件等,以便在不滚动的情况下读取它们.我想对此配置文件做同样的事情.

是否有一种方法来拆分超过一行的字符串?希望,我要求的是显而易见的,但一张照片说千言万语如此,例如,价值,下面.

<add name="validation"
     type="Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF.ValidationElement, Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

如果我打破上面的字符串,请如下所示:

<add name="validation"
     type="Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF.ValidationElement,
     Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

我的应用程序失败:

"创建系统的配置部分处理程序的错误 参数名称:元素"

似乎对字符串中的行中断敏感.

推荐答案

所有排队中断是归一化到空格如果空间分隔符可以处理任意空格,则只需将它们放在一个单独的行上.

本文地址:https://www.itbaoku.cn/post/1938250.html

问题描述

I've got an XML config file with some really long strings. Generally, I format my source files, etc. so that they can be read without scrolling. I'd like to do the same to this config file.

Is there a way to split the string across more than one line? Hopefully, what I'm asking for is obvious but a picture says a thousand words so, e.g. value, below.

<add name="validation"
     type="Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF.ValidationElement, Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

If I break the above string to look like this:

<add name="validation"
     type="Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF.ValidationElement,
     Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

my apps fails with:

"An error occurred creating the configuration section handler for system.serviceModel/behaviors: Extension element 'validation' cannot be added to this element. Verify that the extension is registered in the extension collection at system.serviceModel/extensions/behaviorExtensions. Parameter name: element "

It seems that it's sensitive to line-breaks in the string.

推荐答案

All line breaks are normalized to spaces, so just put them on a separate line if the space delimiter can handle arbitrary whitespace.