The difference and application of dtd,xsd in XML

Source: Internet
Author: User
Tags xml parser xmlns
XML is not unfamiliar to us, it has a wide range of uses in enterprise-class applications. Specifically, no longer said, the following describes the difference between dtd,xsd and XSD as an example to see the definition and use of spring.
1.DTD (documnet Type Definition)
A DTD, a document type definition, is an XML constraint schema language that is a validation mechanism for XML files and is part of the XML file composition.
DTDs are an effective way to ensure that the XML document is well-formed by comparing XML documents and DTD files to see if the document conforms to the specification and whether the elements and labels are used correctly. A DTD document contains the definition rules for elements, the rules for defining relationships between elements, the attributes that an element can use, and the entity or symbol rules that can be used.

DTD versus xsd: DTDs are written using non-XML syntax.
DTDs are not extensible, namespaces are not supported, and only a very limited number of data types are available.

2.XSD (XML Schemas Definition)
The XML schema language is also XSD. The XML Schema describes the structure of the XML document.
An XML document can be validated with a specified XML schema to check whether the XML document meets its requirements. The XML schema allows the document designer to specify the structure and content allowed by an XML document, and to check whether an XML document is valid. The XML schema itself is an XML document that conforms to the XML syntax structure. It can be parsed with a common XML parser.
An XML schema defines the elements that appear in the document, the attributes that appear in the document, the child elements, the number of child elements, the order of the child elements, whether the element is empty, the data type of the element and attribute, the default and fixed values of the element or attribute.
XSD is the reason for DTD substitution, one is that the future conditions can be expanded, two is richer and more useful than DTDs, three is written in XML, four is support data type, and five is support namespace.
The advantages of XML schema:
1) XML Schema XML-based, no specific syntax
2) XML schema can parse and process like other XML files
3) The XML schema provides a richer data type than the DTD.
4) XML schema provides an extensible data model.
5) XML schema supports integrated namespaces
6) XML schema supports attribute groups.

3.spring in Spring-beans-2.5.xsd
Java code   <?xml version= "1.0"  encoding= "UTF-8"  standalone= "no"?>        <xsd:schema xmlns= "Http://www.springframework.org/schema/beans"                 xmlns:xsd= "Http://www.w3.org/2001/XMLSchema"                targetnamespace= "/http Www.springframework.org/schema/beans ">                               <!--  base types -->           <xsd: Complextype name= "Identifiedtype"  abstract= "true" >                       <xsd:attribute  Name= "id"  type= "xsd:id";               </xsd:attribute>            </xsd:complexType>               </xsd:schema>  

(1) The schema element is the root element of all XML Schema schema documents, and it is used to declare that the XML document is an XML Schema document. The schema document itself is also an XML document with its own namespace of xmlns:xsd= "Http://www.w3.org/2001/XMLSchema", where XSD is prefixed.
(2) Schema targetnamespace defines the namespace of the new element and attribute defined by the schema. That is, it restricts the defined XML model by restricting the defined element, or the namespace of the property.

use of the XSD file in the configuration file in 4.Spring

Java code <beans xmlns= "Http://www.springframework.org/schema/beans" xmlns:xsi= "Http://www.w3.org/2001/XMLSche Ma-instance "xsi:schemalocation=" Http://www.springframework.org/schema/beans Http://www.springframework.org/sch Ema/beans/spring-beans-2.5.xsd>

</beans>
When you validate an XML instance document using an XML Schema document, you must specify the XML that corresponds to the namespace, in addition to declaring the namespace (xmlns= "Http://www.springframework.org/schema/beans") The location where the schema document is stored.
Use the SchemaLocation property to specify the storage location of the XML Schema document for the namespace, which contains two parts, part of the namespace URI, and the second part is the XML schema file location or URL address identified by the namespace
(xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ spring-beans-2.5.xsd)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.