{"id":1703,"date":"2010-07-20T11:08:43","date_gmt":"2010-07-20T16:08:43","guid":{"rendered":"http:\/\/jianmingli.com\/wp\/?p=1703"},"modified":"2010-07-20T11:11:45","modified_gmt":"2010-07-20T16:11:45","slug":"xml-schema-create-variable-content-container-using-abstract-type","status":"publish","type":"post","link":"https:\/\/jianmingli.com\/wp\/?p=1703","title":{"rendered":"XML Schema: Create Variable Content Container Using Abstract Type"},"content":{"rendered":"<span id=\"Implementation\"><h2>Implementation<\/h2><\/span>\n<p>* Define an abstract base type (PublicationType) to include common elements:<\/p>\n<pre lang=\"xml\">\r\n<xsd:complexType name=\"PublicationType\" abstract=\"true\">\r\n  <xsd:sequence>\r\n    <xsd:element name=\"Title\" type=\"xsd:string\"\/>\r\n    <xsd:element name=\"Author\" type=\"xsd:string\"\r\n      minOccurs=\"0\" maxOccurs=\"unbounded\"\/>\r\n    <xsd:element name=\"Date\" type=\"xsd:gYear\"\/>\r\n  <\/xsd:sequence>\r\n<\/xsd:complexType>\r\n<\/pre>\n<p>* Define concrete types(BookType, MagazineType) to extend abstract type<\/p>\n<pre lang=\"xml\">\r\n<xsd:complexType name=\"BookType\">\r\n  <xsd:complexContent>\r\n    <xsd:extension base=\"PublicationType\">\r\n      <xsd:sequence>\r\n        <xsd:element name=\"ISBN\" type=\"xsd:string\"\/>\r\n        <xsd:element name=\"Publisher\" type=\"xsd:string\"\/>\r\n      <\/xsd:sequence>\r\n    <\/xsd:extension>\r\n  <\/xsd:complexContent>\r\n<\/xsd:complexType>\r\n<\/pre>\n<pre lang=\"xml\">\r\n<xsd:complexType name=\"MagazineType\">\r\n  <xsd:complexContent>\r\n    <xsd:restriction base=\"PublicationType\">\r\n      <xsd:sequence>\r\n        <xsd:element name=\"Title\" type=\"xsd:string\"\/>\r\n        <xsd:element name=\"Author\" type=\"xsd:string\"\r\n          minOccurs=\"0\" maxOccurs=\"0\"\/>\r\n        <xsd:element name=\"Date\" type=\"xsd:gYear\"\/>\r\n      <\/xsd:sequence>\r\n    <\/xsd:restriction>\r\n  <\/xsd:complexContent>\r\n<\/xsd:complexType>\r\n<\/pre>\n<p>* Define container element (Catalogue) to contain an element (Publication) of the abstract type (PublicationType):<\/p>\n<pre lang=\"xml\">\r\n<xsd:element name=\"Catalogue\">\r\n  <xsd:complexType>\r\n    <xsd:sequence>\r\n      <xsd:element name=\"Publication\"\r\n        type=\"PublicationType\"\r\n        maxOccurs=\"unbounded\"\/>\r\n    <\/xsd:sequence>\r\n  <\/xsd:complexType>\r\n<\/xsd:element>\r\n<\/pre>\n<p>* Example<\/p>\n<pre lang=\"xml\">\r\n<?xml version=\"1.0\"?>\r\n<Catalogue xmlns=\"http:\/\/www.catalogue.org\"\r\n  xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\r\n  xsi:schemaLocation=\r\n  \"http:\/\/www.catalogue.org\r\n  Catalogue.xsd\">\r\n  <Book>\r\n    <Title>Illusions The Adventures of a Reluctant Messiah<\/Title>\r\n    <Author>Richard Bach<\/Author>\r\n    <Date>1977<\/Date>\r\n    <ISBN>0-440-34319-4<\/ISBN>\r\n    <Publisher>Dell Publishing Co.<\/Publisher>\r\n  <\/Book>\r\n  <Magazine>\r\n    <Title>Natural Health<\/Title>\r\n    <Date>1999<\/Date>\r\n  <\/Magazine>\r\n  <Book>\r\n    <Title>The First and Last Freedom<\/Title>\r\n    <Author>J. Krishnamurti<\/Author>\r\n    <Date>1954<\/Date>\r\n    <ISBN>0-06-064831-7<\/ISBN>\r\n    <Publisher>Harper &amp; Row<\/Publisher>\r\n  <\/Book>\r\n<\/Catalogue><\/pre>\n<span id=\"Extend_the_schema\"><h2>Extend the schema<\/h2><\/span>\n<p>* Add a new concrete type (CDType)<\/p>\n<pre lang=\"xml\">\r\n<include schemaLocation=\"Catalogue.xsd\"\/>\r\n<complexType name=\"CDType\">\r\n  <complexContent>\r\n    <extension base=\"PublicationType\" >\r\n      <sequence>\r\n        <element name=\"RecordingCompany\" type=\"string\"\/>\r\n      <\/sequence>\r\n    <\/extension>\r\n  <\/complexContent>\r\n<\/complexType>\r\n<\/pre>\n<p>* Example<\/p>\n<pre lang=\"xml\">\r\n<?xml version=\"1.0\"?>\r\n<Catalogue xmlns=\"http:\/\/www.catalogue.org\"\r\n  xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\r\n  xsi:schemaLocation=\r\n  \"http:\/\/www.catalogue.org\r\n  Catalogue.xsd\">\r\n  <Book>\r\n    <Title>Illusions The Adventures of a Reluctant Messiah<\/Title>\r\n    <Author>Richard Bach<\/Author>\r\n    <Date>1977<\/Date>\r\n    <ISBN>0-440-34319-4<\/ISBN>\r\n    <Publisher>Dell Publishing Co.<\/Publisher>\r\n  <\/Book>\r\n  <Magazine>\r\n    <Title>Natural Health<\/Title>\r\n    <Date>1999<\/Date>\r\n  <\/Magazine>\r\n  <Book>\r\n    <Title>The First and Last Freedom<\/Title>\r\n    <Author>J. Krishnamurti<\/Author>\r\n    <Date>1954<\/Date>\r\n    <ISBN>0-06-064831-7<\/ISBN>\r\n    <Publisher>Harper &amp; Row<\/Publisher>\r\n  <\/Book>\r\n  <CD>\r\n    <Title>Timeless Serenity<\/Title>\r\n    <Author>Dyveke Spino<\/Author>\r\n    <Date>1984<\/Date>\r\n    <RecordingCompany>Dyveke Spino Productions<\/RecordingCompany>\r\n  <\/CD>\r\n<\/Catalogue><\/pre>\n<span id=\"Reference\"><h2>Reference<\/h2><\/span>\n<p>* <a href=\"http:\/\/www.xfront.com\/VariableContentContainers.pdf\">http:\/\/www.xfront.com\/VariableContentContainers.pdf<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Implementation * Define an abstract base type (PublicationType) to include common elements: * Define concrete types(BookType, MagazineType) to extend abstract type * Define container element (Catalogue) to contain an element (Publication) of the abstract type (PublicationType): * Example Illusions The &hellip; <a href=\"https:\/\/jianmingli.com\/wp\/?p=1703\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[32],"tags":[],"class_list":["post-1703","post","type-post","status-publish","format-standard","hentry","category-xml"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8cRUO-rt","_links":{"self":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1703","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1703"}],"version-history":[{"count":3,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1703\/revisions"}],"predecessor-version":[{"id":1705,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1703\/revisions\/1705"}],"wp:attachment":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1703"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1703"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1703"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}