XML限制 [英] XML Restrictions

查看:67
本文介绍了XML限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个如下的XML文档,

Hi,

I''ve an XML document like following,

<?xml version="1.0" encoding="utf-8" ?>
<Templates>
    <Currency Type="USD">
        <sheet Name="Sheet1">
            <Placeholder ID ="A1" ValueSource="DB" TableName="Table1" ColumnName="Column1" Visible="true" Readonly="false" Comment="Sample Comment"/>
            <Placeholder ID ="A1" ValueSource="Text" TableName="" ColumnName="" Visible="" Readonly="" Comment=""/>
        </sheet>
        <sheet Name="Sheet2">
            <Placeholder ID ="A1" ValueSource="DB" TableName="Table1" ColumnName="Column1" Visible="true" Readonly="false" Comment="Sample Comment"/>
            <Placeholder ID ="A1" ValueSource="Text" TableName="" ColumnName="" Visible="" Readonly="" Comment=""/>
        </sheet>
    </Currency>
    <Currency Type="SGD">
        <sheet Name="Sheet1">
            <Placeholder ID ="A1" ValueSource="DB" TableName="Table1" ColumnName="Column1" Visible="false" Readonly="false" Comment="Sample Comment"/>
            <Placeholder ID ="A1" ValueSource="Text" TableName="" ColumnName="" Visible="" Readonly="" Comment=""/>
        </sheet>
        <sheet Name="Sheet2">
            <Placeholder ID ="A1" ValueSource="DB" TableName="Table1" ColumnName="Column1" Visible="true" Readonly="false" Comment="Sample Comment"/>
            <Placeholder ID ="A1" ValueSource="Text" TableName="" ColumnName="" Visible="" Readonly="" Comment=""/>
        </sheet>
    </Currency>
</Templates>




相应的XSD是,




The corresponding XSD is,

<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="Templates">
        <xs:complexType>
            <xs:sequence>
                <xs:element maxOccurs="unbounded" name="Currency">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element maxOccurs="unbounded" name="sheet">
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element maxOccurs="unbounded" name="Placeholder">
                                            <xs:complexType>
                                                <xs:attribute name="ID" type="xs:string" use="required" />
                                                <xs:attribute name="ValueSource" type="xs:string" use="required"/>
                                                <xs:attribute name="TableName" type="xs:string" use="required" />
                                                <xs:attribute name="ColumnName" type="xs:string" use="required" />
                                                <xs:attribute name="Visible" type="xs:boolean" use="required" />
                                                <xs:attribute name="Readonly" type="xs:boolean" use="required" />
                                                <xs:attribute name="Comment" type="xs:string" use="required" />
                                            </xs:complexType>
                                        </xs:element>
                                    </xs:sequence>
                                    <xs:attribute name="Name" type="xs:string" use="required" />
                                </xs:complexType>
                            </xs:element>
                        </xs:sequence>
                        <xs:attribute name="Type" type="xs:string" use="required" />
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>



******************************

问题:

我将XML文件用作模板引擎的配置定义.管理员必须为每个模板定义XML文件.我想强制用户只为特定标签从特定列表(例如枚举)输入值.例如...对于元素货币;用于type属性;管理员只能输入USD/SGD/INR.我试图指定限制;但是对于复杂类型,我无法做到.可以帮忙吗?


此致Vinay



******************************

Problem:

I use the XML file as a configuration defination for my template engine. The admin has to define the XML file for each template. I want to enforce user to enter values only from specific list (say enum) for certain tags. For example... for element currency; for the type attribute; admin only should be able to enter USD/SGD/INR. I was trying to specify restrictions; however I could not do it for the complex types. Can some one help please?


Regards, Vinay

推荐答案

我已经解决了问题,

在此添加简单类型和限制,

I got a work around,

Adding simpletype and restriction on that,

<xs:simpleType name="CurrencyList">
        <xs:restriction base="xs:string" id="CurrencyTypes">
            <xs:enumeration value="USD"></xs:enumeration>
        </xs:restriction>
    </xs:simpleType>




并将其指定为属性的类型.然而;我没有将价值作为智慧的一部分.

有人可以帮我这个忙吗?预先感谢.




and specifying this as type for the atribute. However; I am not getting the values as a part of intellisence.

Can someone help me on this please. Thanks in advance.


好了,上面的代码现在可以正常工作了. VS能够识别枚举中指定的选项.

XSD没有正确映射到XML文件.

想知道,为什么我们不能直接为复杂类型创建限制?如果可以,请提出解决方案.
Well the above code is working fine now. VS is able to identify the options specified in the enum.

XSD was not properly mapped to the XML file.

Want to know, why can''t we create restrictions for the complex types directly? If we can, please suggest a solution.


这篇关于XML限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆