Search code examples
regexxsdbiztalkxsd-validationbiztalk-schemas

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 '|'). 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 '|' char.

Every line in flat file is a single record and there are 10 fields in every record. so there must me exact 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. Currently I am testing with .*(?!([^\r\n\|])).* but it doesn't work when there are more than 9 '|' chars however it works when there are less than 9.

Finally I want a XSD regex which must not allow a new line char and '|' in string but can have empty '' value.

I have referred below links to create my regex,

XML Schema Regular Expressions

XML Schema - Regular Expressions


Solution

  • 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. 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.