I have an xml fragment for which I need to write XSD
<
Use the below two schemas
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://xmlns.oracle.com/sca/1.0" xmlns:id="http://xmlns.oracle.com/id/1.0" xmlns:sca="http://xmlns.oracle.com/sca/1.0">
<xs:import namespace="http://xmlns.oracle.com/id/1.0" schemaLocation="id.xsd"/>
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element ref="sca:service"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="service">
<xs:complexType>
<xs:attribute name="name" use="required" type="xs:NCName"/>
<xs:attribute ref="id:number" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
For ID
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://xmlns.oracle.com/id/1.0" xmlns:id="http://xmlns.oracle.com/id/1.0" xmlns:sca="http://xmlns.oracle.com/sca/1.0">
<xs:import namespace="http://xmlns.oracle.com/sca/1.0" schemaLocation="Untitled2.xsd"/>
<xs:attribute name="number" type="xs:integer"/>
</xs:schema>
You actually need at least as many XSD files as namespaces since one XSD file can target only one namespace, or none.
Since your root element is in one namespace, and the attribute in another, you need then two files at least. You "link" them through an xsd:import.
Top XSD:
<?xml version="1.0" encoding="utf-8"?>
<!--XML Schema generated by QTAssistant/XML Schema Refactoring (XSR) Module (http://www.paschidev.com)-->
<xsd:schema xmlns="http://xmlns.oracle.com/sca/1.0" xmlns:id="http://xmlns.oracle.com/id/1.0" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://xmlns.oracle.com/sca/1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:import schemaLocation="xsd-syntax-for-xml-attributes-with-namespace1.xsd" namespace="http://xmlns.oracle.com/id/1.0" />
<xsd:element name="root">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="service">
<xsd:complexType>
<xsd:attribute name="name" type="xsd:string" use="required" />
<xsd:attribute ref="id:number" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
xsd-syntax-for-xml-attributes-with-namespace1.xsd
<?xml version="1.0" encoding="utf-8"?>
<!--XML Schema generated by QTAssistant/XML Schema Refactoring (XSR) Module (http://www.paschidev.com)-->
<xsd:schema xmlns="http://xmlns.oracle.com/id/1.0" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://xmlns.oracle.com/id/1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:attribute name="number" type="xsd:unsignedShort" />
</xsd:schema>