In XML Schema, can mixed content restrict the type

2020-04-16 08:21发布

In XML Schema, one can use the "mixed" attribute on a <complexType> to allow it to contain text as well as child elements.

My question is whether there is any way to constrain what type of textual content is allowed, when using the "mixed" attribute. For instance, can I specify that the text must represent a floating-point number?

标签: xml xsd
1条回答
够拽才男人
2楼-- · 2020-04-16 09:01

No, you cannot place constraints on the mixed content's text nodes. You can constrain the elements of the mixed content as usual, but the actual mixed-in text is free from constraints.

I'm afraid W3C XML Schema's definition of mixed content is kind of slapped onto complex content in a not-too-thorough way. If Schema made a better abstraction of nodes with shared ground between text, elements, processing instructions and the like, like DOM does, it'd work better. But as it stands, I do believe you're out of luck.

Maybe someone with a tighter grasp on the actual XML Schema spec can confirm/deny this.

查看更多
登录 后发表回答