Home  >  Article  >  Backend Development  >  Four steps of writing XML documents based on Schema

Four steps of writing XML documents based on Schema

黄舟
黄舟Original
2017-02-16 15:35:301911browse

The Schema constraint document itself is an XML document with the extension xsd


##Difficulties :XMLHow to write the root element of the document?

Following 4 steps:

a, first look at the Schema document and find the root element
<?xml version="1.0"encoding="UTF-8"?>
<书架></书架>
b, Thinking: Which namespace does the bookshelf come from? Looking at the Schema document, targetNamespace is the namespace.
Use the xmlns keyword (xmlns namespace declaration) to declare which namespace my elements come from (xmlns: xml namespace)

<?xml version="1.0"encoding="UTF-8"?>
<itcast:书架 xmlns:itcast="http://www.itcast.cn"></itcast:书架>

c, thinking: Which xsd file does the namespace correspond to? Use the schemaLocation keyword to associate the corresponding relationship between the namespace and xsd
<?xml version="1.0"encoding="UTF-8"?>
<itcast:书架 xmlns:itcast="http://www.itcast.cn"
                     schemaLocation="http://www.itcast.cnbook.xsd"></itcast:书架>


Just leave the remaining tasks to eclipse to automatically generate it.

The case is as follows:

The known Schema constraint document is as follows, write the corresponding xml document


<?xml version="1.0" encoding="UTF-8" ?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
					  targetNamespace="http://www.itcast.cn"
					  elementFormDefault="qualified">
	<xs:element name=&#39;书架&#39; >
		<xs:complexType>
			<xs:sequence maxOccurs=&#39;unbounded&#39; >
				<xs:element name=&#39;书&#39; >
					<xs:complexType>
						<xs:sequence>
							<xs:element name=&#39;书名&#39; type=&#39;xs:string&#39; />
							<xs:element name=&#39;作者&#39; type=&#39;xs:string&#39; />
							<xs:element name=&#39;售价&#39; type=&#39;xs:integer&#39; />
						</xs:sequence>
					</xs:complexType>
				</xs:element>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
</xs:schema>

xml document is as follows :


##

<?xml version="1.0" encoding="UTF-8"?>
<itcast:书架 xmlns:itcast="http://www.itcast.cn"
				xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
				xsi:schemaLocation="http://www.itcast.cn book.xsd">
	<itcast:书>
		<itcast:书名>JavaScript网页开发</itcast:书名>
		<itcast:作者>张孝祥</itcast:作者>
		<itcast:售价>28</itcast:售价>
	</itcast:书>

</itcast:书架>


Final version: Created in a flash sale.

You can create it directly through the Myeclipse tool.


The above is the content of the four steps of writing XML documents based on Schema. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn