How to write XSD for an XML File

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • asma1400
    New Member
    • Jan 2021
    • 1

    How to write XSD for an XML File

    This is my XML File:

    Code:
    <?xml version="1.0" encoding="UTF-8" ?> <rooms xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="room.xsd">
     <room> 
    <capacity>2 Adults</capacity>
     <room_name>King Double</room_name> <cost_st>$1700</cost_st> 
    <cost_lt>$3400</cost_lt> 
    <loc>Ground Floor</loc>
     <photo>fraise.jpg</photo> </room> </rooms>
    This is my attempt at XSD, it's not working
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    
     <xs:complexType name="Image">
                                     <xs:simpleContent>
                                                <xs:extension base="xs:anyURI">
                                                     <xs:attribute name="src" type="xs:string"/>
                                                     </xs:extension>
                                      </xs:simpleContent>
                             </xs:complexType>
                             
            <xs:element name="rooms">
            <xs:complexType>
    <xs:sequence>
    
    <xs:element name="room" minOccurs="1" maxOccurs="unbounded">
     <xs:element name="capacity" type="xs:string"/>
                               <xs:element name="room_name" type="xs:string"/>
                               <xs:element name="cost_st" type="xs:string"/>
                               <xs:element name="cost_lt" type="Image"/>
             <xs:element name="loc" type="xs:string"/>
                               <xs:element name="photo" type="xs:Image"/>
            
          </xs:element>
          </xs:sequence>
          </xs:complexType>
          </xs:element>
          </xs:schema>
    Last edited by Niheel; Jan 5 '21, 01:07 PM.
Working...