0

This may be close to duplicate of the question here. But this is not the same. After reading the above answer I know what code must be added for my scenario, but I am unable to figure out where to put it. This is my current xsd file

<tns:element name="WSO2Lanka">
    <tns:complexType>
        <tns:sequence>
            <tns:element name="Employees" type="EmployeeBaseType">
            </tns:element>
        </tns:sequence>
    </tns:complexType>
</tns:element>

<tns:complexType name="EmployeeBaseType">
    <tns:sequence>
        <tns:element name="Employee" type="EmployeType">
        </tns:element>
    </tns:sequence>
</tns:complexType>

<tns:complexType name="EmployeType">
    <tns:sequence>
        <tns:element name="name" type="nameType">
        </tns:element>
        <tns:element name="company" type="tns:string"></tns:element>
        <tns:element name="position" type="tns:string"></tns:element>
        <tns:element name="address" type="addressType"></tns:element>
        <tns:element name="tele" type="tns:string"></tns:element>

    </tns:sequence>

</tns:complexType>

<tns:complexType name="nameType">
    <tns:sequence>
        <tns:element name="fname" type="tns:string">
        </tns:element>
        <tns:element name="lname" type="tns:string">
        </tns:element>
    </tns:sequence>
</tns:complexType>

<tns:complexType name="addressType">
    <tns:sequence>
        <tns:element name="city" type="tns:string"></tns:element>
        <tns:element name="province" type="tns:string"></tns:element>

    </tns:sequence>
</tns:complexType>

and this is what I needed in my xml file.

<?xml version="1.0" encoding="UTF-8"?>
<WSO2Lanka xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="../EmployeeXMLSchema.xsd">
    <Employees>
        <Employee eid="001">
            <name>
                <fname>kasun</fname>
                <lname>Siyambalapitiya</lname>
            </name>
            <company>WSO2</company>
            <position>intern</position>
            <address>
                <city>Kuliyapitiya</city>
                <province>North Western</province>
            </address>
            <tele>0715523333</tele>
        </Employee>
    </Employees>
</WSO2Lanka>

As in the xml I need to have an attribute for the element Employee as eidof the type of ID I know that the below code is the one to be added, can you please help me to figure this out. Thanks in advance

<tns:complexType>
    <tns:simpleContent>
        <tns:extension base="tns:ID">

            <tns:attribute name="edi" type="tns:ID" use="required"></tns:attribute>

        </tns:extension>

    </tns:simpleContent>
</tns:complexType>

1 Answer 1

0

Could you please give a try by updating "EmployeType" as below (added attribute in complexType after close of sequence element) ?

<tns:complexType name="EmployeType">
<tns:sequence>
    <tns:element name="name" type="nameType">
    </tns:element>
    <tns:element name="company" type="tns:string"></tns:element>
    <tns:element name="position" type="tns:string"></tns:element>
    <tns:element name="address" type="tns1:addressType"></tns:element>
    <tns:element name="tele" type="tns:string"></tns:element>

</tns:sequence>
<tns:attribute name="eid" type="tns:string"/>   

Added below line in your "EmployeeType" definition.

***<tns:attribute name="eid" type="tns:string"/>***
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the answer, I'll try it later and let you know if it worked

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.