{"id":125,"date":"2025-11-24T11:59:55","date_gmt":"2025-11-24T03:59:55","guid":{"rendered":"https:\/\/www.52runoob.com\/?p=125"},"modified":"2025-11-24T11:59:55","modified_gmt":"2025-11-24T03:59:55","slug":"%e8%af%a6%e8%a7%a3xml%e7%bc%96%e7%a8%8b%e4%b8%ad%e7%9a%84%e6%a8%a1%e5%bc%8f%e5%ae%9a%e4%b9%89xsd","status":"publish","type":"post","link":"https:\/\/www.52runoob.com\/index.php\/2025\/11\/24\/%e8%af%a6%e8%a7%a3xml%e7%bc%96%e7%a8%8b%e4%b8%ad%e7%9a%84%e6%a8%a1%e5%bc%8f%e5%ae%9a%e4%b9%89xsd\/","title":{"rendered":"\u8be6\u89e3XML\u7f16\u7a0b\u4e2d\u7684\u6a21\u5f0f\u5b9a\u4e49XSD"},"content":{"rendered":"\n<p>\u592a\u597d\u4e86\u2014\u2014\u4e0b\u9762\u7ed9\u4f60\u4e00\u4efd <strong>\u8be6\u5c3d\u3001\u5b9e\u7528\u4e14\u5e26\u793a\u4f8b\u7684 XSD\uff08XML Schema Definition\uff09\u6df1\u5165\u6307\u5357<\/strong>\uff0c\u5305\u542b\u6982\u5ff5\u3001\u8bed\u6cd5\u3001\u5e38\u7528\u6a21\u5f0f\u3001\u8fdb\u9636\u6280\u5de7\u3001\u9a8c\u8bc1\u793a\u4f8b\u4e0e\u5e38\u89c1\u9677\u9631\u3002\u76ee\u6807\u662f\u8ba9\u4f60\u4e0d\u4ec5\u4f1a\u8bfb\u61c2 XSD\uff0c\u8fd8\u80fd\u5199\u51fa\u5065\u58ee\u3001\u53ef\u590d\u7528\u7684\u6a21\u5f0f\u6587\u4ef6\u5e76\u5728\u4ee3\u7801\u4e2d\u6821\u9a8c XML\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"># XSD \u6982\u89c8 \u2014 \u5b83\u662f\u4ec0\u4e48\u3001\u4e3a\u5565\u7528<\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>XSD\uff08XML Schema Definition\uff09<\/strong> \u662f W3C \u6807\u51c6\uff0c\u7528\u4e8e\u63cf\u8ff0 XML \u6587\u6863\u7684\u7ed3\u6784\u3001\u5143\u7d20\/\u5c5e\u6027\u7684\u7c7b\u578b\u4e0e\u7ea6\u675f\u3002<\/li>\n\n\n\n<li>\u4e0e DTD \u76f8\u6bd4\uff0cXSD \u66f4\u5f3a\u5927\uff1a\u652f\u6301\u6570\u636e\u7c7b\u578b\uff08\u6574\u6570\u3001\u65e5\u671f\u7b49\uff09\u3001\u547d\u540d\u7a7a\u95f4\u3001\u590d\u6742\u7c7b\u578b\u7ee7\u627f\u3001\u7ea6\u675f\uff08pattern\u3001min\/max\uff09\u7b49\u3002<\/li>\n\n\n\n<li>\u5178\u578b\u7528\u9014\uff1a\u914d\u7f6e\u6821\u9a8c\u3001WebService \u6d88\u606f\u3001\u6587\u6863\u683c\u5f0f\u89c4\u8303\u3001\u63a5\u53e3\u5951\u7ea6\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">1 \u57fa\u672c\u6784\u6210\u4e0e\u547d\u540d\u7a7a\u95f4\uff08\u9aa8\u67b6\u793a\u4f8b\uff09<\/h1>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;\n&amp;lt;xs:schema xmlns:xs=&quot;http:\/\/www.w3.org\/2001\/XMLSchema&quot;\n           targetNamespace=&quot;http:\/\/example.com\/book&quot;\n           xmlns=&quot;http:\/\/example.com\/book&quot;\n           elementFormDefault=&quot;qualified&quot;&gt;\n    &amp;lt;!-- \u5728\u8fd9\u91cc\u58f0\u660e\u5168\u5c40\u5143\u7d20\/\u7c7b\u578b --&gt;\n&amp;lt;\/xs:schema&gt;\n\n<\/pre><\/div>\n\n\n<p>\u5173\u952e\u5c5e\u6027\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>xmlns:xs<\/code>\uff1aXSD \u7684\u547d\u540d\u7a7a\u95f4\uff08\u56fa\u5b9a\uff09\u3002<\/li>\n\n\n\n<li><code>targetNamespace<\/code>\uff1a\u8be5 schema \u5b9a\u4e49\u6240\u5c5e\u4e8e\u7684\u547d\u540d\u7a7a\u95f4\uff08Instance XML \u7684\u5143\u7d20\u901a\u5e38\u5c5e\u4e8e\u6b64\u547d\u540d\u7a7a\u95f4\uff09\u3002<\/li>\n\n\n\n<li><code>elementFormDefault=\"qualified\"<\/code>\uff1a\u9ed8\u8ba4\u8981\u6c42\u5728\u5b9e\u4f8b\u4e2d\u4f7f\u7528\u547d\u540d\u7a7a\u95f4\u524d\u7f00\u6216\u9ed8\u8ba4\u547d\u540d\u7a7a\u95f4\u6765\u9650\u5b9a\u5143\u7d20\uff08\u63a8\u8350\u7528\u4e8e\u516c\u5171 schema\uff09\u3002<\/li>\n\n\n\n<li><code>attributeFormDefault<\/code>\uff1a\u5f71\u54cd\u5c5e\u6027\u662f\u5426\u9700\u8981\u9650\u5b9a\uff0c\u9ed8\u8ba4\u901a\u5e38\u662f <code>unqualified<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">2 \u57fa\u672c\u6784\u4ef6\uff08element\u3001attribute\u3001simpleType\u3001complexType\uff09<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">2.1 \u58f0\u660e\u5143\u7d20\uff08element\uff09<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5168\u5c40\u5143\u7d20<\/strong>\uff08\u53ef\u88ab\u5f15\u7528\uff09\uff1a\u76f4\u63a5\u4f5c\u4e3a <code>&lt;xs:element name=\"Book\"><\/code> \u653e\u5728 schema \u6839\u4e0b\u3002<\/li>\n\n\n\n<li><strong>\u5c40\u90e8\u5143\u7d20<\/strong>\uff1a\u5b9a\u4e49\u5728 complexType \u5185\uff0c\u4f5c\u7528\u57df\u5c40\u9650\u4e8e\u7236\u5143\u7d20\u3002<\/li>\n<\/ul>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;xs:element name=&quot;Title&quot; type=&quot;xs:string&quot;\/&gt;\n\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">2.2 \u5c5e\u6027\uff08attribute\uff09<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;xs:attribute name=&quot;id&quot; type=&quot;xs:ID&quot; use=&quot;required&quot;\/&gt;\n\n<\/pre><\/div>\n\n\n<p><code>use<\/code> \u53ef\u4ee5\u662f <code>optional<\/code> \/ <code>required<\/code> \/ <code>prohibited<\/code>\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2.3 \u7b80\u5355\u7c7b\u578b\uff08simpleType\uff09<\/h2>\n\n\n\n<p>\u7528\u4e8e\u5bf9\u6587\u672c\/\u539f\u59cb\u503c\u8fdb\u884c\u7ea6\u675f\uff08\u679a\u4e3e\u3001pattern\u3001\u957f\u5ea6\u3001\u6570\u503c\u8303\u56f4\u7b49\uff09\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;xs:simpleType name=&quot;ISBNType&quot;&gt;\n  &amp;lt;xs:restriction base=&quot;xs:string&quot;&gt;\n    &amp;lt;xs:pattern value=&quot;\\d{3}-\\d{10}&quot;\/&gt;\n  &amp;lt;\/xs:restriction&gt;\n&amp;lt;\/xs:simpleType&gt;\n\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">2.4 \u590d\u6742\u7c7b\u578b\uff08complexType\uff09<\/h2>\n\n\n\n<p>\u5305\u542b\u5b50\u5143\u7d20\u548c\/\u6216\u5c5e\u6027\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;xs:complexType name=&quot;BookType&quot;&gt;\n  &amp;lt;xs:sequence&gt;\n    &amp;lt;xs:element name=&quot;Title&quot; type=&quot;xs:string&quot;\/&gt;\n    &amp;lt;xs:element name=&quot;Author&quot; type=&quot;xs:string&quot;\/&gt;\n  &amp;lt;\/xs:sequence&gt;\n  &amp;lt;xs:attribute name=&quot;id&quot; type=&quot;xs:string&quot; use=&quot;required&quot;\/&gt;\n&amp;lt;\/xs:complexType&gt;\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">3 \u5185\u5bb9\u6a21\u578b\u5173\u952e\u6784\u9020\uff08sequence \/ choice \/ all \/ any\uff09<\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>&lt;xs:sequence><\/code>\uff1a\u6309\u987a\u5e8f\u51fa\u73b0\uff08\u5e38\u7528\uff09\u3002<\/li>\n\n\n\n<li><code>&lt;xs:choice><\/code>\uff1a\u591a\u4e2a\u5019\u9009\uff0c\u6700\u591a\u4e00\u4e2a\u51fa\u73b0\u3002<\/li>\n\n\n\n<li><code>&lt;xs:all><\/code>\uff1a\u5b50\u5143\u7d20\u53ef\u4efb\u610f\u987a\u5e8f\uff0c\u4f46\u53ea\u80fd\u51fa\u73b0 0 \u6216 1 \u6b21\uff08\u53d7\u9650\uff09\u3002<\/li>\n\n\n\n<li><code>&lt;xs:any><\/code>\uff1a\u901a\u914d\u7b26\uff0c\u5141\u8bb8\u4efb\u610f\u547d\u540d\u7a7a\u95f4\u7684\u5143\u7d20\uff08\u914d\u5408 processContents\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u4f8b\uff1a<code>choice<\/code> \u793a\u4f8b\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;xs:choice&gt;\n  &amp;lt;xs:element name=&quot;Email&quot; type=&quot;xs:string&quot;\/&gt;\n  &amp;lt;xs:element name=&quot;Phone&quot; type=&quot;xs:string&quot;\/&gt;\n&amp;lt;\/xs:choice&gt;\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">4 \u5143\u7d20\u51fa\u73b0\u6b21\u6570\uff08minOccurs \/ maxOccurs\uff09<\/h1>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;xs:element name=&quot;Book&quot; type=&quot;BookType&quot; minOccurs=&quot;0&quot; maxOccurs=&quot;unbounded&quot;\/&gt;\n\n<\/pre><\/div>\n\n\n<ul class=\"wp-block-list\">\n<li><code>maxOccurs=\"unbounded\"<\/code> \u8868\u793a\u53ef\u91cd\u590d\u4efb\u610f\u6b21\uff08\u5e38\u7528\u4e8e\u5217\u8868\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">5 \u7c7b\u578b\u6d3e\u751f\uff08\u7ee7\u627f\uff09\u2014 extension \/ restriction<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">5.1 \u6269\u5c55\uff08extension\uff09<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;xs:complexType name=&quot;EBookType&quot;&gt;\n  &amp;lt;xs:complexContent&gt;\n    &amp;lt;xs:extension base=&quot;BookType&quot;&gt;\n      &amp;lt;xs:sequence&gt;\n        &amp;lt;xs:element name=&quot;DownloadUrl&quot; type=&quot;xs:anyURI&quot;\/&gt;\n      &amp;lt;\/xs:sequence&gt;\n    &amp;lt;\/xs:extension&gt;\n  &amp;lt;\/xs:complexContent&gt;\n&amp;lt;\/xs:complexType&gt;\n\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">5.2 \u9650\u5b9a\uff08restriction\uff09<\/h2>\n\n\n\n<p>\u9650\u5236\u57fa\u7c7b\u578b\u53ef\u80fd\u7684\u5185\u5bb9\uff08\u66f4\u4e25\u683c\uff09\u3002\u5c11\u7528\u4f46\u6709\u573a\u666f\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">6 \u9ad8\u7ea7\uff1asimpleType \u7684 facets\uff08\u7ea6\u675f\u9762\u5143\uff09<\/h1>\n\n\n\n<p>\u5e38\u7528 facets\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>enumeration<\/code>\uff08\u679a\u4e3e\uff09<\/li>\n\n\n\n<li><code>pattern<\/code>\uff08\u6b63\u5219\uff09<\/li>\n\n\n\n<li><code>minLength<\/code> \/ <code>maxLength<\/code> \/ <code>length<\/code><\/li>\n\n\n\n<li><code>minInclusive<\/code> \/ <code>maxInclusive<\/code> \/ <code>minExclusive<\/code> \/ <code>maxExclusive<\/code><\/li>\n\n\n\n<li><code>fractionDigits<\/code> \/ <code>totalDigits<\/code><\/li>\n<\/ul>\n\n\n\n<p>\u793a\u4f8b\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;xs:simpleType name=&quot;CurrencyType&quot;&gt;\n  &amp;lt;xs:restriction base=&quot;xs:decimal&quot;&gt;\n    &amp;lt;xs:minInclusive value=&quot;0.00&quot;\/&gt;\n    &amp;lt;xs:fractionDigits value=&quot;2&quot;\/&gt;\n  &amp;lt;\/xs:restriction&gt;\n&amp;lt;\/xs:simpleType&gt;\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">7 \u5168\u5c40\u7c7b\u578b vs \u5c40\u90e8\u7c7b\u578b\uff08\u8bbe\u8ba1\u9009\u62e9\uff09<\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5168\u5c40\u7c7b\u578b\uff08named type\uff09<\/strong>\uff1a\u53ef\u590d\u7528\uff0c\u9002\u5408\u516c\u5171\u6a21\u578b\u3002<\/li>\n\n\n\n<li><strong>\u5c40\u90e8\u7c7b\u578b\uff08anonymous\uff09<\/strong>\uff1a\u53ea\u5728\u5355\u4e2a\u5143\u7d20\u4f7f\u7528\uff0c\u7b80\u6d01\u4f46\u4e0d\u53ef\u590d\u7528\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u5efa\u8bae\uff1a\u516c\u5171 API \u4f7f\u7528\u547d\u540d\u7c7b\u578b\uff0c\u4fbf\u4e8e\u7ef4\u62a4\u4e0e\u7248\u672c\u7ba1\u7406\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">8 \u547d\u540d\u7a7a\u95f4\u548c\u5bfc\u5165\uff08import \/ include \/ redefine\uff09<\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>&lt;xs:include schemaLocation=\"other.xsd\"\/><\/code>\uff1a\u5408\u5e76\u540c\u4e00\u547d\u540d\u7a7a\u95f4\u4e0b\u7684 schema\u3002<\/li>\n\n\n\n<li><code>&lt;xs:import namespace=\"...\" schemaLocation=\"...\"\/><\/code>\uff1a\u5bfc\u5165\u4e0d\u540c\u547d\u540d\u7a7a\u95f4\u7684 schema\uff08\u5e38\u7528\u4e8e\u590d\u5408\u6587\u6863\uff09\u3002<\/li>\n\n\n\n<li><code>&lt;xs:redefine><\/code>\uff1a\u91cd\u5b9a\u4e49\u5df2\u5305\u542b\u7c7b\u578b\uff08\u4e0d\u5e38\u7528\uff0c\u8c28\u614e\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">9 \u6ce8\u91ca\u4e0e\u6587\u6863\uff08\u8ba9 schema \u53ef\u8bfb\uff09<\/h1>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;xs:annotation&gt;\n  &amp;lt;xs:documentation xml:lang=&quot;en&quot;&gt;Book type definition.&amp;lt;\/xs:documentation&gt;\n&amp;lt;\/xs:annotation&gt;\n\n<\/pre><\/div>\n\n\n<p>\u5bf9\u5916 API \u6587\u6863\u5316\u5f88\u6709\u7528\uff08\u5f88\u591a\u5de5\u5177\u4f1a\u63d0\u53d6\u8fd9\u4e9b\u8bf4\u660e\uff09\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">10 \u5e38\u7528\u6a21\u5f0f\u793a\u4f8b\uff1aBookstore XSD\uff08\u5b8c\u6574\u793a\u4f8b\uff09<\/h1>\n\n\n\n<p>\u8fd9\u662f\u4e00\u4e2a\u7efc\u5408\u793a\u4f8b\uff0c\u8986\u76d6\u5143\u7d20\u3001\u5c5e\u6027\u3001simple\/complex\u3001\u679a\u4e3e\u3001\u51fa\u73b0\u6b21\u6570\u4e0e\u7ee7\u627f\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;\n&amp;lt;xs:schema xmlns:xs=&quot;http:\/\/www.w3.org\/2001\/XMLSchema&quot;\n           targetNamespace=&quot;http:\/\/example.com\/bookstore&quot;\n           xmlns=&quot;http:\/\/example.com\/bookstore&quot;\n           elementFormDefault=&quot;qualified&quot;&gt;\n\n  &amp;lt;!-- \u7b80\u5355\u7c7b\u578b\uff1aISBN --&gt;\n  &amp;lt;xs:simpleType name=&quot;ISBNType&quot;&gt;\n    &amp;lt;xs:restriction base=&quot;xs:string&quot;&gt;\n      &amp;lt;xs:pattern value=&quot;\\d{3}-\\d{10}&quot;\/&gt;\n    &amp;lt;\/xs:restriction&gt;\n  &amp;lt;\/xs:simpleType&gt;\n\n  &amp;lt;!-- \u679a\u4e3e\u7c7b\u578b\uff1a\u8d27\u5e01 --&gt;\n  &amp;lt;xs:simpleType name=&quot;CurrencyType&quot;&gt;\n    &amp;lt;xs:restriction base=&quot;xs:string&quot;&gt;\n      &amp;lt;xs:enumeration value=&quot;CNY&quot;\/&gt;\n      &amp;lt;xs:enumeration value=&quot;USD&quot;\/&gt;\n      &amp;lt;xs:enumeration value=&quot;EUR&quot;\/&gt;\n    &amp;lt;\/xs:restriction&gt;\n  &amp;lt;\/xs:simpleType&gt;\n\n  &amp;lt;!-- Book \u590d\u6742\u7c7b\u578b --&gt;\n  &amp;lt;xs:complexType name=&quot;BookType&quot;&gt;\n    &amp;lt;xs:sequence&gt;\n      &amp;lt;xs:element name=&quot;Title&quot; type=&quot;xs:string&quot;\/&gt;\n      &amp;lt;xs:element name=&quot;Author&quot; type=&quot;xs:string&quot; minOccurs=&quot;1&quot; maxOccurs=&quot;unbounded&quot;\/&gt;\n      &amp;lt;xs:element name=&quot;Price&quot; minOccurs=&quot;1&quot;&gt;\n        &amp;lt;xs:complexType&gt;\n          &amp;lt;xs:simpleContent&gt;\n            &amp;lt;xs:extension base=&quot;xs:decimal&quot;&gt;\n              &amp;lt;xs:attribute name=&quot;currency&quot; type=&quot;CurrencyType&quot; use=&quot;required&quot;\/&gt;\n            &amp;lt;\/xs:extension&gt;\n          &amp;lt;\/xs:simpleContent&gt;\n        &amp;lt;\/xs:complexType&gt;\n      &amp;lt;\/xs:element&gt;\n      &amp;lt;xs:element name=&quot;ISBN&quot; type=&quot;ISBNType&quot; minOccurs=&quot;0&quot;\/&gt;\n    &amp;lt;\/xs:sequence&gt;\n    &amp;lt;xs:attribute name=&quot;id&quot; type=&quot;xs:ID&quot; use=&quot;required&quot;\/&gt;\n  &amp;lt;\/xs:complexType&gt;\n\n  &amp;lt;!-- \u5168\u5c40\u5143\u7d20 --&gt;\n  &amp;lt;xs:element name=&quot;Book&quot; type=&quot;BookType&quot;\/&gt;\n  &amp;lt;xs:element name=&quot;Bookstore&quot;&gt;\n    &amp;lt;xs:complexType&gt;\n      &amp;lt;xs:sequence&gt;\n        &amp;lt;xs:element ref=&quot;Book&quot; minOccurs=&quot;0&quot; maxOccurs=&quot;unbounded&quot;\/&gt;\n      &amp;lt;\/xs:sequence&gt;\n    &amp;lt;\/xs:complexType&gt;\n  &amp;lt;\/xs:element&gt;\n\n&amp;lt;\/xs:schema&gt;\n\n<\/pre><\/div>\n\n\n<p>\u5bf9\u5e94\u7684 XML \u5b9e\u4f8b\uff08\u5408\u683c\uff09\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;?xml version=&quot;1.0&quot;?&gt;\n&amp;lt;Bookstore xmlns=&quot;http:\/\/example.com\/bookstore&quot;&gt;\n  &amp;lt;Book id=&quot;b1&quot;&gt;\n    &amp;lt;Title&gt;\u4eba\u7c7b\u7b80\u53f2&amp;lt;\/Title&gt;\n    &amp;lt;Author&gt;\u5c24\u74e6\u5c14\u00b7\u8d6b\u62c9\u5229&amp;lt;\/Author&gt;\n    &amp;lt;Price currency=&quot;CNY&quot;&gt;45.00&amp;lt;\/Price&gt;\n    &amp;lt;ISBN&gt;978-1234567890&amp;lt;\/ISBN&gt;\n  &amp;lt;\/Book&gt;\n&amp;lt;\/Bookstore&gt;\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">11 \u9a8c\u8bc1 XML \u7684\u4ee3\u7801\u793a\u4f8b<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">Java\uff08JAXP\uff09<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);\nSchema schema = factory.newSchema(new File(&quot;bookstore.xsd&quot;));\nValidator validator = schema.newValidator();\nvalidator.validate(new StreamSource(new File(&quot;bookstore.xml&quot;))); \/\/ \u629b\u5f02\u5e38\u5219\u9a8c\u8bc1\u5931\u8d25\n\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">Python\uff08lxml\uff09<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nfrom lxml import etree\nxml_doc = etree.parse(&#039;bookstore.xml&#039;)\nxmlschema_doc = etree.parse(&#039;bookstore.xsd&#039;)\nxmlschema = etree.XMLSchema(xmlschema_doc)\nxmlschema.assertValid(xml_doc)  # \u82e5\u65e0\u5f02\u5e38\u5219\u9a8c\u8bc1\u901a\u8fc7\n\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">\u547d\u4ee4\u884c\uff08\u5e38\u89c1\uff09<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>xmllint --noout --schema bookstore.xsd bookstore.xml<\/code>\uff08\u82e5\u7cfb\u7edf\u6709 <code>xmllint<\/code>\uff09<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">12 \u8fdb\u9636\u7279\u6027\uff08\u5feb\u901f\u6d4f\u89c8\uff09<\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>substitutionGroup<\/strong>\uff1a\u5141\u8bb8\u7528\u4e00\u7ec4\u5143\u7d20\u4e92\u6362\u66ff\u4ee3\u67d0\u4e2a\u5143\u7d20\uff08\u5b9e\u73b0\u7c7b\u4f3c\u591a\u6001\uff09\u3002<\/li>\n\n\n\n<li><strong>abstract elements<\/strong>\uff1a\u62bd\u8c61\u5143\u7d20\u4e0d\u80fd\u51fa\u73b0\u5728\u5b9e\u4f8b\u4e2d\uff0c\u4f46\u53ef\u4ee5\u88ab substitution \u66ff\u6362\u3002<\/li>\n\n\n\n<li><strong>xs:any \/ processContents<\/strong>\uff1a\u63a5\u7eb3\u672a\u77e5\u6269\u5c55\u5143\u7d20\uff08lax\/strict\/skip\uff09\u3002<\/li>\n\n\n\n<li><strong>mixed=&#8221;true&#8221;<\/strong>\uff1a\u590d\u6742\u7c7b\u578b\u80fd\u540c\u65f6\u5305\u542b\u6587\u672c\u4e0e\u5b50\u5143\u7d20\uff08\u5e38\u89c1\u4e8e\u5bcc\u6587\u672c\u573a\u666f\uff09\u3002<\/li>\n\n\n\n<li><strong>redefine<\/strong>\uff1a\u5728\u5305\u542b\u7684 schema \u4e0a\u91cd\u5b9a\u4e49\u7c7b\u578b\uff08\u6bd4\u8f83\u5371\u9669\uff0c\u614e\u7528\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u4f8b\uff1a<code>mixed<\/code>\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;xs:complexType name=&quot;Paragraph&quot; mixed=&quot;true&quot;&gt;\n  &amp;lt;xs:sequence&gt;\n    &amp;lt;xs:element name=&quot;em&quot; type=&quot;xs:string&quot; minOccurs=&quot;0&quot;\/&gt;\n  &amp;lt;\/xs:sequence&gt;\n&amp;lt;\/xs:complexType&gt;\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">13 \u8bbe\u8ba1\u4e0e\u7ef4\u62a4\u7684\u6700\u4f73\u5b9e\u8df5\uff08\u7ecf\u9a8c\u8981\u70b9\uff09<\/h1>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u628a\u5e38\u7528\u7c7b\u578b\u62bd\u6210\u5168\u5c40\u547d\u540d\u7c7b\u578b<\/strong>\uff08\u4fbf\u4e8e\u590d\u7528\u548c\u7248\u672c\u5347\u7ea7\uff09\u3002<\/li>\n\n\n\n<li><strong>\u4f7f\u7528 <code>elementFormDefault=\"qualified\"<\/code><\/strong> \u4fdd\u8bc1\u5143\u7d20\u90fd\u88ab\u547d\u540d\u7a7a\u95f4\u9650\u5b9a\uff0c\u51cf\u5c11\u51b2\u7a81\u3002<\/li>\n\n\n\n<li><strong>\u5199\u6ce8\u91ca\uff08xs:annotation\/xs:documentation\uff09<\/strong> \u2014 schema \u4e5f\u8981\u50cf API \u6587\u6863\u3002<\/li>\n\n\n\n<li><strong>\u4f7f\u7528\u679a\u4e3e &amp; pattern \u51cf\u5c11\u6b67\u4e49<\/strong>\uff08\u5c24\u5176\u662f\u4ee3\u7801\u5bf9\u63a5\u65f6\uff09\u3002<\/li>\n\n\n\n<li><strong>\u907f\u514d\u8fc7\u5ea6\u4f7f\u7528 xs:any \/ lax<\/strong>\uff0c\u4f1a\u653e\u677e\u7ea6\u675f\u3001\u964d\u4f4e\u6821\u9a8c\u4ef7\u503c\u3002<\/li>\n\n\n\n<li><strong>\u7ed9\u5927 schema \u5206\u6a21\u5757\uff08\u4f7f\u7528 include\/import\uff09<\/strong>\uff0c\u4fbf\u4e8e\u56e2\u961f\u534f\u4f5c\u3002<\/li>\n\n\n\n<li><strong>\u7a33\u5b9a\u7684\u547d\u540d\u7a7a\u95f4\u4e0e\u7248\u672c\u7b56\u7565<\/strong>\uff1a\u901a\u8fc7 URI \u6216 schemaLocation + \u7248\u672c\u53f7\u7ba1\u7406\u6f14\u8fdb\u3002<\/li>\n\n\n\n<li><strong>\u4e3a\u5e38\u89c1\u9519\u8bef\u7f16\u5199\u6e05\u6670\u7684\u9519\u8bef\u6d88\u606f\u4e0e\u793a\u4f8b XML<\/strong>\uff0c\u4f7f\u7528\u8005\u66f4\u5bb9\u6613\u8c03\u8bd5\u3002<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">14 \u5e38\u89c1\u9519\u8bef\u4e0e\u6392\u67e5\u6280\u5de7<\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5b9e\u4f8b\u5143\u7d20\u627e\u4e0d\u5230\uff08\u627e\u4e0d\u5230\u5143\u7d20\uff09<\/strong>\uff1a\u901a\u5e38\u662f\u547d\u540d\u7a7a\u95f4\u4e0d\u5339\u914d\uff08instance \u6ca1\u6709\u58f0\u660e targetNamespace \u6216\u524d\u7f00\u9519\u8bef\uff09\u3002<\/li>\n\n\n\n<li><strong>\u7c7b\u578b\u4e0d\u5339\u914d\uff08\u4f8b\u5982 xs:decimal\uff09<\/strong>\uff1a\u68c0\u67e5\u6587\u672c\u662f\u5426\u7b26\u5408 facets\uff08\u6bd4\u5982\u5c0f\u6570\u70b9\u4f4d\u7f6e\uff09\u3002<\/li>\n\n\n\n<li><strong>\u5143\u7d20\u987a\u5e8f\u9519\u8bef<\/strong>\uff1a\u82e5\u4f7f\u7528 <code>sequence<\/code>\uff0c\u987a\u5e8f\u5fc5\u987b\u4e25\u683c\u4e00\u81f4\uff1b\u6539\u4e3a <code>all<\/code> \u6216 <code>choice<\/code> \u5982\u6709\u9700\u8981\u3002<\/li>\n\n\n\n<li><strong>\u5c5e\u6027\u5fc5\u987b\/\u53ef\u9009\u641e\u6df7<\/strong>\uff1a\u6ce8\u610f <code>use=\"required\"<\/code>\u3002<\/li>\n\n\n\n<li><strong>ID\/IDREF \u672a\u6b63\u786e\u5f15\u7528<\/strong>\uff1aID \u5fc5\u987b\u552f\u4e00\uff0cIDREF \u5fc5\u987b\u80fd\u89e3\u6790\u5230\u67d0\u4e2a ID\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u8c03\u8bd5\u5efa\u8bae\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4f7f\u7528\u80fd\u663e\u793a\u8be6\u7ec6\u9519\u8bef\u4fe1\u606f\u7684\u9a8c\u8bc1\u5668\uff08IDE\u3001xmllint\u3001lxml \u90fd\u4f1a\u6307\u51fa\u884c\u5217\u4e0e\u9519\u8bef\u7ec6\u8282\uff09\u3002<\/li>\n\n\n\n<li>\u68c0\u67e5 schema \u7684\u547d\u540d\u7a7a\u95f4\u4e0e\u5b9e\u4f8b\u58f0\u660e\u662f\u5426\u4e00\u81f4\uff08<code>xmlns<\/code>\u3001\u524d\u7f00\u3001targetNamespace\uff09\u3002<\/li>\n\n\n\n<li>\u5c06\u590d\u6742 schema \u62c6\u5206\u5e76\u5355\u72ec\u9a8c\u8bc1\u5c0f\u7247\u6bb5\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">15 \u5c0f\u7ed3\u901f\u67e5\uff08Cheat-List\uff09<\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>xs:schema<\/code>\u3001<code>targetNamespace<\/code>\u3001<code>elementFormDefault<\/code><\/li>\n\n\n\n<li>\u5143\u7d20\uff1a<code>xs:element<\/code>\uff08name\/type\/ref\uff09<\/li>\n\n\n\n<li>\u7c7b\u578b\uff1a<code>xs:simpleType<\/code> \/ <code>xs:complexType<\/code><\/li>\n\n\n\n<li>\u5185\u5bb9\u6a21\u578b\uff1a<code>sequence<\/code> \/ <code>choice<\/code> \/ <code>all<\/code> \/ <code>any<\/code><\/li>\n\n\n\n<li>\u7ea6\u675f\uff1a<code>minOccurs<\/code> \/ <code>maxOccurs<\/code> \/ facets\uff08pattern\u3001enumeration\u3001length\uff09<\/li>\n\n\n\n<li>\u6d3e\u751f\uff1a<code>xs:extension<\/code> \/ <code>xs:restriction<\/code><\/li>\n\n\n\n<li>\u5f15\u5165\uff1a<code>xs:include<\/code> \/ <code>xs:import<\/code> \/ <code>xs:redefine<\/code><\/li>\n\n\n\n<li>\u9a8c\u8bc1 API\uff1aJAXP\uff08Java\uff09\u3001lxml\uff08Python\uff09\u3001xmllint\uff08\u547d\u4ee4\u884c\uff09<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u592a\u597d\u4e86\u2014\u2014\u4e0b\u9762\u7ed9\u4f60\u4e00\u4efd \u8be6\u5c3d\u3001\u5b9e\u7528\u4e14\u5e26\u793a\u4f8b\u7684 XSD\uff08XML Schema De&#8230; <a class=\"more-link\" href=\"https:\/\/www.52runoob.com\/index.php\/2025\/11\/24\/%e8%af%a6%e8%a7%a3xml%e7%bc%96%e7%a8%8b%e4%b8%ad%e7%9a%84%e6%a8%a1%e5%bc%8f%e5%ae%9a%e4%b9%89xsd\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-125","post","type-post","status-publish","format-standard","hentry","category-xml-xslt"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/125","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/comments?post=125"}],"version-history":[{"count":1,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/125\/revisions"}],"predecessor-version":[{"id":126,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/125\/revisions\/126"}],"wp:attachment":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/media?parent=125"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/categories?post=125"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/tags?post=125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}