Four steps of writing XML documents based on Schema

黄舟
Release: 2017-02-16 15:35:30
Original
1948 people have browsed it

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"?>
<书架></书架>
Copy after login
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:书架>
Copy after login

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:书架>
Copy after login


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>
Copy after login

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:书架>
Copy after login


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)!


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!