xsd for complex element structure

Hi all, I have a piece of xml for which I am trying to create the xsd equivalent: <stream onid='01' tsid='90' streamname='ASTRA1'> <service sid='7f3'>bbc</service> <service sid='722'>tg4</service> <service sid='233'/> </stream> The onid and tsid attributes are required but the streamname attribute is optional. The service tag can occur zero or an unbounded number of times. The sid attribute is required. I have come up with the following piece of xsd to define the schema for the xml above: <xsd:element name="stream" minOccurs="0"> <xsd:complexType> <xsd:sequence> <xsd:element name="service" minOccurs="0"> <xsd:complexType> <xsd:attribute name="sid" type="xsd:string" use="required"/> </xsd:complexType> </xsd:element> </xsd:sequence> <xsd:attribute name="onid" type="xsd:string" use="required"/> <xsd:attribute name="tsid" type="xsd:string" use="required"/> <xsd:attribute name="streamname" type="xsd:string"/> </xsd:complexType> </xsd:element>

Your schema will work only for element with attributes, and no textual content. i.e

is for ELEMENTS WITH ATTRIBUTES BUT NO CONTENT !!!

A more complicated definition would be for an elemnt with textual content and an attribute. You would have to use the simpleContent tag inside the complex type to achive that !! So here is the code !!!

And few more suggestions :-) The minOccurs should not be set to 0 as it woul mean that you are giving a default value of 1 for maxOccurs. A betetr thing would be to give "unbounded" as I have Try to make a complex type and then make an elemnt as that type !!!. Even more better way would be to create an attribute group. The code is as follows :-)