I am new to xml, I have one xml file and I created an xsd schema for this file, but my problem is how to reference this schema in an XML file. My xml schema looks like this:
<?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:wmh="http://www.wmhelp.com/2003/eGenerator" elementFormDefault="qualified" targetNamespace="http://axis.com/service" xmlns="http://axis.com/service" version="1.0"> <xs:element name="SWService" type="SWServiceType"/> <xs:element name="HWService" type="HWServiceType"/> <xs:complexType name="SWServiceType"> <xs:sequence> <xs:element name="Service" type="ServiceType" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> <xs:complexType name="ServiceType"> <xs:complexContent> <xs:extension base="IdType"> <xs:sequence> <xs:element name="Description" type="xs:string" maxOccurs="1" minOccurs="0"/> <xs:element name="ServiceCustomers" type="ServiceCustomersType" maxOccurs="1" minOccurs="0"/> <xs:element name="ServiceSuppliers" type="ServiceSuppliersType" maxOccurs="1" minOccurs="0"/> </xs:sequence> <xs:attribute name="Name" type="xs:string" use="required"/> </xs:extension> </xs:complexContent> </xs:complexType> <xs:complexType name="HWServiceType"> <xs:sequence> <xs:element name="element" type="elementGroupType" maxOccurs="1" minOccurs="0"/> </xs:sequence> </xs:complexType> <xs:complexType name="ServiceCustomersType"> <xs:sequence> <xs:element name="SoftWare" type="SoftWareType" maxOccurs="unbounded" minOccurs="0"/> </xs:sequence> </xs:complexType> <xs:complexType name="ServiceSuppliersType"> <xs:sequence> <xs:element name="SoftWare" type="SoftWareType" maxOccurs="unbounded" minOccurs="0"/> <xs:element name="HardWare" type="HardWareType" maxOccurs="unbounded" minOccurs="0"/> </xs:sequence> </xs:complexType> <xs:complexType name="SoftWareType"> <xs:complexContent> <xs:extension base="PathType"> <xs:attribute name="Service" type="xs:string" use="required"/> </xs:extension> </xs:complexContent> </xs:complexType> <xs:complexType name="HardWareType"> <xs:complexContent> <xs:extension base="PathType"> <xs:attribute name="Type" type="xs:string" use="required"/> <xs:attribute name="Nr" type="xs:string" use="required"/> <xs:attribute name="Service" type="xs:string" use="required"/> </xs:extension> </xs:complexContent> </xs:complexType> <xs:complexType name="PathType"> <xs:attribute name="Path" type="xs:string" use="required"/> </xs:complexType> <xs:complexType name="elementGroupType"> <xs:sequence> <xs:element name="element" type="elementType" maxOccurs="unbounded" minOccurs="1"/> </xs:sequence> </xs:complexType> <xs:complexType name="elementType"> <xs:sequence> <xs:element name="LM" type="LMType2" maxOccurs="1" minOccurs="1"/> <xs:element name="Service" type="ServiceType" maxOccurs="unbounded" minOccurs="0"/> </xs:sequence> <xs:attribute name="Type" type="xs:string" use="required"/> <xs:attribute name="Nr" type="xs:string" use="required"/> <xs:attribute name="Name" type="xs:string" use="required"/> </xs:complexType> <xs:complexType name="LMType2"> <xs:sequence> <xs:element name="LowerMode" type="LowerModeType2" maxOccurs="unbounded" minOccurs="0"/> </xs:sequence> </xs:complexType> <xs:complexType name="LowerModeType2"> <xs:complexContent> <xs:extension base="IdType"> <xs:attribute name="Probability" type="xs:double" use="required"/> </xs:extension> </xs:complexContent> </xs:complexType> <xs:complexType name="IdType"> <xs:attribute name="Id" type="xs:string" use="required"/> </xs:complexType> </xs:schema>
I saved this file as service.xsd. I need to refer to this schema in my XML file, I tried it this way but did not check it.
<?xml version="1.0" encoding="UTF-8"?> <Service xsi:schemaLocation="file:///C:/main/newfolder/service.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://axis.com/service" Version="1.0"> --------Xml data------- </Service>
I canβt understand what the problem is. This gives an error like this
No DTD of the document found
I tried like this
<?xml version="1.0" encoding="UTF-8"?> <Service xsi:schemaLocation=""http://axis.com/service" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://axis.com/service" Version="1.0"> --------Xml data------- </Service>
but still the same problem. when i check the xml file using xmlpad. Can anyone fix my problem. Thanks for the help.
Thanks in advance.
source share