About XSD and DTD in XML structure and the use of standalone
XmlDeclaration declare= document. Createxmldeclaration ("1.0", "Utf-8", "yes"); Yes is the value of standalone,
There is a standalone in the declaration in XML
Standalone is used to indicate whether the file calls other external files. A value of "yes" indicates that no external file is being called, and if the value is "no" then there is a call to the external file. The default value is "Yes".
What is the difference between an external file referred to here or a search for XML as a valid constraint file, or a DTD or schema?
Although XML1.0 provides a mechanism for document type definition (DTD) to standardize the formatting rules of XML. But it is inherently flawed, for example, by using non-XML syntax rules, not supporting more data types, extensibility
, in order to overcome these shortcomings, XML Schema appears. It is recommended to use XML schemas instead of DTDs in XML.
XML Schemas (schemas), like DTDs, are also used to define constraints on XML documents. But unlike DTDs, XML schemas follow XML syntax rules to better support data types and namespaces.
"The XML Schema is a XML based alternative to DTD," said the consortium. Schemas are defined in a separate file, typically with an. xsd extension. Each schema definition has a schema for the root element that belongs to the name null
Room The schema element can contain optional properties.
Like what:
<xs:schema Xmlns:xs=http://www.w3.org/2001/xmlschema elementformdefault= "qualified" attributeFormDefault= " Unqualified ">
This indicates that the elements used in the pattern come from the namespace.
The XML file is linked to the corresponding pattern using the schemalocation attribute in the schema namespace. The schema namespace must be defined using the SchemaLocation property.
All of these definitions appear in the root element of the XML document.
The syntax is as follows:
<root_element schema_namespace_definition schema_location_definition>
Here is an example:
<books xmlns:xs= "books.xsd" >
Let's take a look at an XML file example (Message.xml) that describes the file with a DTD and XML Schema, to see the difference between them:
1. Using DTDs:
- <?xml version= "1.0" standalone= "yes"?>
- <! DOCTYPE message [
- <! ELEMENT message (To,from,body) >
- <! ELEMENT to (#PCDATA) >
- <! ELEMENT from (#PCDATA) >
- <! ELEMENT Body (#PCDATA) >
- ] >
2. The DTD structure definition of message:
- <message>
- <to>rose</to>
- <from>alex</from>
- <body>hi,my girl!</body>
- </message>
3. Use XML Schema:
Message.xml:
- <?xml version= "1.0" standalone= "no"? >
- <message xmlns=http://www.example.com xmlns:xsi=http://www.w3.org/2001/xmlschema-instance xsi:schemaLocation= " Message.xsd ">
- <to>Rose</to>
- <from>Alex</from>
- <body>hi,my girl!</body>
- </message>
4. The XSD XML schema structure of message is defined:
Message.xsd:
- <?xml version= "1.0"?>
- <xs:schema xmlns:xs=http://www.w3.org/2001/xmlschema targetnamespace=http://www.example.com xmlns= "" elementformdefault= "qualified" >
- <xs:element name= "Message" >
- <xs:complexType>
- <xs:sequence>
- <xs:element name= "to" type= "xs:string"/>
- <xs:element name= "from" type= "xs:string"/>
- <xs:element name= "Body" type= "xs:string"/>
- </xs:sequence>
- </xs:complexType>
- </xs:element>
- </xs:schema>
XSD and DTD in XML and the use of standalone