开发者

case-insensitive key in xsd

I have an XSD embedded into an XML like this:

<Replacements>
    <xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <xs:element name="Replacem开发者_高级运维ents">
            <xs:complexType>
                <xs:sequence>
                    <xs:element minOccurs="0" maxOccurs="unbounded" ref="Replace" />
                </xs:sequence>
            </xs:complexType>
            <xs:key name="ReplaceKey">
                <xs:selector xpath="./Replace"/>
                <xs:field xpath="@old"/>
            </xs:key>
        </xs:element>
        <xs:element name="Replace">
            <xs:complexType>
                <xs:attribute name="old" type="AnythingButLowerCase" use="required" />
                <xs:attribute name="new" type="xs:string" use="required" />
            </xs:complexType>
        </xs:element>
        <xs:simpleType name="AnythingButLowerCase">
            <xs:restriction base="xs:string">
                <xs:pattern value="[^a-z]+"/>
            </xs:restriction>
        </xs:simpleType>
    </xs:schema>
    <Replace old="A1020____9" new="A1020"/>
    <Replace old="a1020____9" new="A1020"/>
</Replacements>

I've used xs:key to define a unique-key on "old" attribute of Replace elements.

my problem is I want this key to be CASE-INSENSITIVE.

I've read so many documents indicating I can use xsd functions like upper-case or translate to solve this, but if I write something like

<xs:field xpath="upper-case(@old)"/>

VS2010 gives me a warning like this:

'upper-case(@old)' is an invalid XPath for selector or field.

What is it I'm doing wrong?

Thanks :)


The correct XPath function is "upper-case", not "upper case". Just add in the hyphen.


OK!
I got that!

Using functions in an xpath for a xs:field is not allowed.

The workaround for what I was seeking is to define a simpleType and put a restriction there not allowing lower-case letters.
Something like this:

<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<Replacements>
    <xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <xs:element name="Replacements">
            <xs:complexType>
                <xs:sequence>
                    <xs:element minOccurs="0" maxOccurs="unbounded" ref="Replace" />
                </xs:sequence>
            </xs:complexType>
            <xs:key name="ReplaceKey">
                <xs:selector xpath="./Replace"/>
                <xs:field xpath="@old"/>
            </xs:key>
        </xs:element>
        <xs:element name="Replace">
            <xs:complexType>
                <xs:attribute name="old" type="AnythingButLowerCase" use="required" />
                <xs:attribute name="new" type="xs:string" use="required" />
            </xs:complexType>
        </xs:element>
        <xs:simpleType name="AnythingButLowerCase">
            <xs:restriction base="xs:string">
                <xs:pattern value="[^a-z]+"/>
            </xs:restriction>
        </xs:simpleType>
    </xs:schema>
    <Replace old="A1020____9" new="A1020"/>
    <Replace old="a1020____9" new="A1020"/>
</Replacements>

Now this serves as what I want it to.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜