简体   繁体   English

使用正则表达式的平面文件架构验证-不允许换行和定界符char

[英]Flat file schema validation using regular expression - not allow new line and delimiter char

I know this must be primitive question but I am still not able to find a solution to my simple problem. 我知道这一定是原始问题,但仍然无法找到我的简单问题的解决方案。

In a BizTalk solution, I want to validate a inbound flat file against a flat file schema (Delimiter char is pipe '|'). 在BizTalk解决方案中,我想针对平面文件架构(分隔符char是管道'|')验证入站平面文件。 The rule is that there must be exact same number of fields in every record (every line). 规则是每条记录(每行)中的字段数必须完全相同。 So after disassembling, none of the field must have new line char (CR LF or \\r\\n) and pipe '|' 因此,在拆卸之后,所有字段都不得包含换行符(CR LF或\\ r \\ n)和管道'|' char. 焦炭。

Every line in flat file is a single record and there are 10 fields in every record. 平面文件中的每一行都是一条记录,每条记录中有10个字段。 so there must me exact 9 '|' 所以我必须精确到9'|' pipe chars in every line. 在每行中使用管道字符。

I tried to solve it using XSD regular expression validation but since regex is not my area of expertise, I am not able to create a final regex. 我试图使用XSD正则表达式验证来解决它,但是由于regex不是我的专业领域,因此我无法创建最终的regex。 Currently I am testing with .*(?!([^\\r\\n\\|])).* but it doesn't work when there are more than 9 '|' 目前,我正在使用。*(?!([^ \\ r \\ n \\ |]))。*进行测试,但是当存在9个以上的'|'时,它将不起作用 chars however it works when there are less than 9. 字符数,但少于9时有效。

Finally I want a XSD regex which must not allow a new line char and '|' 最后,我想要一个XSD正则表达式,该正则表达式必须不允许换行char和'|' in string but can have empty '' value. 字符串形式,但可以具有空的''值。

I have referred below links to create my regex, 我已通过下面的链接创建了我的正则表达式,

XML Schema Regular Expressions XML模式正则表达式

XML Schema - Regular Expressions XML模式-正则表达式

I think you're trying to solve the wrong problem. 我认为您正在尝试解决错误的问题。

First, do you really need to do this? 首先,您真的需要这样做吗? I don't recall ever needing or even considering what you're describing. 我不记得曾经需要甚至考虑过您所描述的内容。

Second, you can just Validate the parsed Xml. 其次,您只需验证已解析的Xml。 If the field count is wrong, it will fail there. 如果字段计数错误,它将在那里失败。 If you really need to check for extra '|', you can put that in the Schema to test for it in a Map. 如果您确实需要检查额外的'|',可以将其放在Schema中以在Map中进行测试。

IBM Integration Bus solves this problem by allowing you to describe the non-XML data format using an XSD. IBM Integration Bus通过允许您使用XSD描述非XML数据格式来解决此问题。 The technology is called Data Format Description Language (DFDL). 该技术称为数据格式描述语言(DFDL)。 https://en.wikipedia.org/wiki/Data_Format_Description_Language https://en.wikipedia.org/wiki/Data_Format_Description_Language

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM