XSD restriction pattern for accented characters

2019-08-03 04:55发布

I working with XML/XSD files, but i have one problem with the validation.

One field has this restriction:

<xs:pattern value="[A-Za-z0-9 '\-\./]+"/>

But when I put this value:

example with àccented character

The validator says that "The Pattern constraint failed"

So basically, what I'm asking is: Are accented characters included in the a-z pattern?

If not, what can I do? (Consider that I'm not able to change the .xsd because it's not mine and I'm not allowed.)

1条回答
2楼-- · 2019-08-03 05:23

No, accented characters are not included in the [A-Za-z] pattern.

If you could change the XSD, and if you want a much more general Unicode-based pattern, you could specify:

<xs:pattern value="[\p{L}\p{P}\p{N}]+"/>

Explanation:

  • \p{L} matches a letter
  • \p{P} matches a punctuation character (to pick up your apostrophe request)
  • \p{N} matches a number
  • [...]+ matches one or more of its containing characters.

If you cannot change the XSD, and if you wish for your document to be valid by it, you should abide by its constraints. There could be reasons other than neglect that the XSD precludes non-ASCII code points. For example, consuming applications may expect or even require ASCII there.

查看更多
登录 后发表回答