Generate XML and XSD

Question:

Generate XML and XSD from the below Entity-Relationship diagram

Quiz for Exam - Generate XML and XSD

Give all the element names in lowercase.

Code:

company.xml

<company>
    <companyname>ABC</companyname>
    <address>Mumbai</address>
    <department>
        <dname>IT</dname>
        <deptphoneno>9999999</deptphoneno>
        <deptfaxno>12345679</deptfaxno>
        <deptemail>IT@gmail.com</deptemail>
        <employee>
            <empid>1</empid>
            <ename>pulkit</ename>
            <emailid>pulkit@gmail.com</emailid>
            <phoneno>1111111111</phoneno>
        </employee>
    </department>
    <department>
        <dname>EEE</dname>
        <deptphoneno>7890000</deptphoneno>
        <deptfaxno>90100000</deptfaxno>
        <deptemail>EEE@email.com</deptemail>
        <employee>
            <empid>2</empid>
            <ename>x</ename>
            <emailid>x@gmail.com</emailid>
            <phoneno>123456781</phoneno>
        </employee>
        <contractemployee>
            <name>contract1</name>
            <phoneno>2345781</phoneno>
        </contractemployee>
    </department>
</company>

company.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    
    <xs:element name="company">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="companyname" type="xs:string"/>
                <xs:element name="address" type="xs:string"/>

                <xs:element name="department" maxOccurs="unbounded">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="dname" type="xs:string"/>
                            <xs:element name="deptphoneno" type="xs:integer"/>
                            <xs:element name="deptfaxno" type="xs:integer"/>
                            <xs:element name="deptemail" type="xs:string"/>

                            <xs:element name="employee" maxOccurs="unbounded">
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element name="empid" type="xs:integer"/>
                                        <xs:element name="ename" type="xs:string"/>
                                        <xs:element name="emailid" type="xs:string"/>
                                        <xs:element name="phoneno" type="xs:integer"/>
                                    </xs:sequence>
                                </xs:complexType>
                            </xs:element>

                            <xs:element name="contractemployee" minOccurs="0" maxOccurs="unbounded">
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element name="name" type="xs:string"/>
                                        <xs:element name="phoneno" type="xs:integer"/>
                                    </xs:sequence>
                                </xs:complexType>
                            </xs:element>

                        </xs:sequence>
                    </xs:complexType>
                </xs:element>

            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

Recommended:

Leave a Comment

Your email address will not be published. Required fields are marked *

x