Click here to Skip to main content
15,851,387 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I've an XML document like following,

XML
<?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>



The corresponding XSD is,

XML
<?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>


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

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
Posted

I got a work around,

Adding simpletype and restriction on that,

XML
<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.
 
Share this answer
 
v2
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900