是否可以在 XML 文件中将字符串拆分为多行?如果是这样,如何? [英] Is it possible to split a string across multiple lines in an XML file? If so, how?
问题描述
我有一个包含一些非常长的字符串的 XML 配置文件.通常,我格式化我的源文件等,以便无需滚动即可阅读.我想对这个配置文件做同样的事情.
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" />
我的应用程序失败:
为 system.serviceModel/behaviors 创建配置节处理程序时发生错误:无法将扩展元素验证"添加到此元素.请验证扩展是否已在位于 system.serviceModel/extensions/behaviorExtensions 的扩展集合中注册.参数名称:元素
"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.
这篇关于是否可以在 XML 文件中将字符串拆分为多行?如果是这样,如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!