Correct way to use key in xsd

前端 未结 1 1167
有刺的猬
有刺的猬 2021-01-14 08:35

I\'m writing an XSD schema for a project I\'m working on. The schema below is one I took from a microsoft example and modified slightly.

I am trying to use the key a

1条回答
  •  -上瘾入骨i
    2021-01-14 09:12

    I'm not 100 % sure, but my pretty confident guess is that the XPath expression in the selector element does not care about the target namespace, just the namespaces you've declared with xmlns attributes. So, since you haven't declared a default namespace, it tries to ensure elements part in no namespace are unique. And since the part elements in your document seem to be in the namespace1 namespace, you don't have any part elements in no namespace, so this uniqueness constraint succeeds.

    You can verify my guess by adding to your schema element the attribute xmlns="namespace1". (Since all your elements in the schema document have prefixes, this is the only thing you need to do.) If your commented-out key element works then, this would seem to be the correct explanation.

    EDIT: Okay, I found the answer. Turns out that, in XPath 1.0, when you have a non-prefixed name, it is automatically interpreted as being in no namespace. There is no way to set the default namespace in XPath 1.0, so you always need to prefix all names in XPath expressions when they are in some namespace. So no matter whether you've declared a default namespace in your schema document, the commented out key definition is trying to match names in no namespace, which doesn't match your document.

    0 讨论(0)
提交回复
热议问题