Generate well formed XML document 4

Question:

Create XML document from the following XSD schema

<?xml version=”1.0″ encoding=”UTF-8″?>

<xsd:schema xmlns:xsd=”http://www.w3.org/2001/XMLSchema”>

    <xsd:element name=”creditcard”>

        <xsd:complexType>

            <xsd:sequence>

                <xsd:element maxOccurs=”unbounded” minOccurs=”1″ name=”card” type=”type”/>

            </xsd:sequence>

        </xsd:complexType>

    </xsd:element>

    <xsd:complexType name=”type”>

        <xsd:sequence>

            <xsd:element name=”cardnumber” type=”xsd:string”/>

            <xsd:element name=”fname” type=”xsd:string”/>

            <xsd:element name=”lname” type=”xsd:string”/>

            <xsd:element name=”address” type=”xsd:string”/>

            <xsd:element name=”limit” type=”xsd:integer”/>

            <xsd:element maxOccurs=”unbounded” minOccurs=”0″ name=”prereqid” type=”xsd:string”/>

            <xsd:element maxOccurs=”unbounded” minOccurs=”1″ name=”statement” type=”statementType”/>

        </xsd:sequence>

    </xsd:complexType>

    <xsd:complexType name=”statementType”>

        <xsd:sequence>

            <xsd:element name=”stateid” type=”xsd:integer”/>

            <xsd:element name=”statedate” type=”xsd:date”/>

            <xsd:element maxOccurs=”unbounded” minOccurs=”1″ name=”statecharge” type=”chargeType”/>

        </xsd:sequence>

    </xsd:complexType>

    <xsd:complexType name=”chargeType”>

        <xsd:sequence>

            <xsd:element name=”cid” type=”xsd:string”/>

            <xsd:element name=”camount” type=”xsd:decimal”/>

            <xsd:element name=”cdate” type=”xsd:date”/>

            <xsd:element name=”cbusiness” type=”xsd:string”/>

        </xsd:sequence>

    </xsd:complexType>

</xsd:schema>

Code:

creditcard.xml

<?xml version="1.0" encoding="UTF-8"?>
<creditcard xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="creditcard.xsd">
    <card>
        <cardnumber>12345</cardnumber>
        <fname>Akanksha</fname>
        <lname>Deb</lname>
        <address>lal street</address>
        <limit>3</limit>
        <statement>
            <stateid>1234</stateid>
            <statedate>1999-06-09</statedate>
            <statecharge>
                <cid>shivani</cid>
                <camount>90000.01</camount>
                <cdate>2022-03-15</cdate>
                <cbusiness>busy</cbusiness>
            </statecharge>
        </statement>
    </card>
</creditcard>

Recommended:

Leave a Comment

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

x