我必须根据给定框架的XML代码编写模式。例如:
我试过写一个架构,但我感到迷茫......
XML文件代码:
<Albums>
<artist personorgroup="person" groupmembernames="N/A" artistorgroupcountry="United States"
careerBegin="2015" careerend="N/A" artistName="Cardi B" genre="Rap">
<album albumCategory="Grammy Nominee" albumName="Invasion of Privacy" sku="K315SPR19A"
type="album">
<Comment> Absolute trash, it's a travesty this won a Grammy </Comment>
<Rating> 13/13 </Rating>
<albumArt> Cardi B.jpg <!-- Found from albumartexchange.com -->
</albumArt>
<releases>
<release release="Invasion of Privacy (clean lyrics)" releasedate="2018-04-05"
recordlabel="Atlantic (Warner Music imprint), KSR Group"
recordlabelcatalognumber="N/A" barcodenumber="075679873675" country="US"
format="Digital Media"> </release>
<release release="Invasion of Privacy (explicit)"
releasedate="2018-04-05 / 2018-04-06 / 2018-04-06"
recordlabel="Atlantic (Warner Music imprint), KSR Group"
recordlabelcatalognumber="N/A" barcodenumber="075679873682"
country="XW
CA
US"
format="Digital Media"> </release>
</releases>
<Songs>
<song songposition="1" songlength="3:51"
songcomposersandwriters="Sean Allen / Belcalis Almanzar / Maurice Jordan / Jermaine Preyan / James SwanQo / Anthony Tucker / Robert Williams"
songName="Get Up 10" sku="K315SPR19A001" albumref="K315SPR19A" type="song"> </song>
<song songposition="2" songlength="4:23"
songcomposersandwriters="Belcalis Almanzar / Kirsnick Ball / Kiari Cephus / Joshua Cross / Quavious Marshall"
songName="Drip (feat. Migos)" sku="K315SPR19A002" albumref="K315SPR19A"
type="song"> </song>
<song songposition="3" songlength="3:01"
songcomposersandwriters="Belcalis Almanzar / James Foye III / Philip Coleman, Jr. / Austin Owens / Jordan Thorpe"
songName="Bickenhead" sku="K315SPR19A003" albumref="K315SPR19A" type="song"> </song>
<song songposition="4" songlength="3:43"
songcomposersandwriters="Belcalis Almanzar / Laquan Green / J. White Did It / Dieuson Octave / Klenord Raphael / Jordan Thorpe / Jermaine White"
songName="Bodak Yellow" sku="K315SPR19A004" albumref="K315SPR19A" type="song"> </song>
<song songposition="5" songlength="3:30"
songcomposersandwriters="Belcalis Almanzar / Alan Bergman / Marilyn Bergman / Dennis Coles / Robert Diggs / Adam Feeney / Gary Grice / Marvin Hamlisch / Lamont Hawkins / Anderson Hernandez / Lauryn Hill / Jason Hunter / Russell Jones / Matthew Samuels / Clifford Smith / Jordan Thorpe / U-God / Corey Woods"
songName="Be Careful" sku="K315SPR19A005" albumref="K315SPR19A" type="song"> </song>
<song songposition="6" songlength="4:44"
songcomposersandwriters="Belcalis Almanzar / Chancelor Bennett / Allen Ritter / Matthew Samuels"
songName="Best Life" sku="K315SPR19A006" albumref="K315SPR19A" type="song"> </song>
<song songposition="7" songlength="4:13"
songcomposersandwriters="Belcalis Almanzar / José Álvaro Osorio Balvin / Benito Antonio Martinez Ocasio / Tony Pabon / Manny Rodriguez"
songName="I Like It" sku="K315SPR19A007" albumref="K315SPR19A" type="song"> </song>
<song songposition="8" songlength="2:57"
songcomposersandwriters="Belcalis Almanzar / Khari Cain / Nija Charles / Kehlani Parrish / Mike Riley"
songName="Ring" sku="K315SPR19A008" albumref="K315SPR19A" type="song"> </song>
<song songposition="9" songlength="3:49"
songcomposersandwriters="Belcalis Almanzar / Jordan Thorpe / Jermaine White"
songName="Money Bag" sku="K315SPR19A009" albumref="K315SPR19A" type="song"> </song>
<song songposition="10" songlength="3:44"
songcomposersandwriters="Shayaa Bin Abraham-Joseph / Belcalis Almanzar / Samuel Gloade / Darryl McCorkell"
songName="Bartier Cardi (feat. 21 Savage)" sku="K315SPR19A010"
albumref="K315SPR19A" type="song"> </song>
<song songposition="11" songlength="3:50"
songcomposersandwriters="Belcalis Almanzar / Keenon Jackson / Leslie Andre Wakefield Jr. / Dijon McFarlane"
songName="She Bad" sku="K315SPR19A011" albumref="K315SPR19A" type="song"> </song>
<song songposition="12" songlength="3:08"
songcomposersandwriters="Belcalis Almanzar / Benjamin Levin / Alexandra Tamposi / Justin Tranter / Andrew Wotman"
songName="Thru Your Phone" sku="K315SPR19A012" albumref="K315SPR19A" type="song"> </song>
<song songposition="13" songlength="3:20"
songcomposersandwriters="Belcalis Almanzar / Nija Charles / Kevin Gomringer / Tim Gomringer / Shane Lindstrom / Solana Rowe"
songName="I Do" sku="K315SPR19A013" albumref="K315SPR19A" type="song"> </song>
</Songs>
<producersMixersSongwritersEngineers>
<engineersMixers> Leslie Brathwaite & Evan LaRay </engineersMixers>
<songwriters> Belcalis Almanzar & Jorden Thorpe </songwriters>
<masteringEngineer> Colin Leonard </masteringEngineer>
</producersMixersSongwritersEngineers>
</album>
</artist>
<artist personorgroup="person" groupmembernames="N/A" artistorgroupcountry="United States"
careerBegin="2004" careerend="N/A" artistName="Brandi Carlile" genre="Pop/Rock">
<album albumCategory="Grammy_Nominee" albumName="By The Way, I Forgive You" sku="K315SPR19B"
type="album">
<Comment> Haven't listened, not my taste </Comment>
<Rating> 11/13 </Rating>
<albumArt> Brandi Carlile.jpg <!-- Found from albumartexchange.com -->
</albumArt>
<releases>
<release release="By the Way, I Forgive You" releasedate="2018-02-16"
recordlabel="Elektra (1950–1989, revived 2009–06-01; read annotations before use), Low Country Sound"
recordlabelcatalognumber="565226-2" barcodenumber="075678659188" country="US"
format="CD"> </release>
<release release="By the Way, I Forgive You (mastered for iTunes)"
releasedate="2018-02-16"
recordlabel="Elektra (1950–1989, revived 2009–06-01; read annotations before use)"
recordlabelcatalognumber="N/A" barcodenumber="075679885449" country="US"
format="Digital Media"> </release>
</releases>
<Songs>
<song songposition="1" songlength="4:01"
songcomposersandwriters="Brandi Carlile / Phil Hanseroth / Tim Hanseroth"
songName="Everytime I Hear That Song" sku="K315SPR19B001" albumref="K315SPR19B"
type="song"> </song>
<song songposition="2" songlength="4:39"
songcomposersandwriters="Brandi Carlile / Dave Cobb / Phil Hanseroth / Tim Hanseroth"
songName="The Joke" sku="K315SPR19B002" albumref="K315SPR19B" type="song"> </song>
<song songposition="3" songlength="4:22"
songcomposersandwriters="Brandi Carlile / Phil Hanseroth / Tim Hanseroth"
songName="Hold Out Your Hand" sku="K315SPR19B003" albumref="K315SPR19B"
type="song"> </song>
<song songposition="4" songlength="3:16"
songcomposersandwriters="Brandi Carlile / Phil Hanseroth / Tim Hanseroth"
songName="The Mother" sku="K315SPR19B004" albumref="K315SPR19B" type="song"> </song>
<song songposition="5" songlength="4:07"
songcomposersandwriters="Brandi Carlile / Phil Hanseroth / Tim Hanseroth"
songName="Whatever You Do" sku="K315SPR19B005" albumref="K315SPR19B" type="song"> </song>
<song songposition="6" songlength="4:43"
songcomposersandwriters="Brandi Carlile / Phil Hanseroth / Tim Hanseroth"
songName="Fulton County Jane Doe" sku="K315SPR19B006" albumref="K315SPR19B"
type="song"> </song>
<song songposition="7" songlength="4:28"
songcomposersandwriters="Brandi Carlile / Phil Hanseroth / Tim Hanseroth"
songName="Sugartooth" sku="K315SPR19B007" albumref="K315SPR19B" type="song"> </song>
<song songposition="8" songlength="3:51"
songcomposersandwriters="Brandi Carlile / Phil Hanseroth / Tim Hanseroth"
songName="Most of All" sku="K315SPR19B008" albumref="K315SPR19B" type="song"> </song>
<song songposition="9" songlength="4:06"
songcomposersandwriters="Brandi Carlile / Phil Hanseroth / Tim Hanseroth"
songName="Harder to Forgive" sku="K315SPR19B009" albumref="K315SPR19B"
type="song"> </song>
<song songposition="10" songlength="5:47"
songcomposersandwriters="Brandi Carlile / Phil Hanseroth / Tim Hanseroth"
songName="Party of One" sku="K315SPR19B10" albumref="K315SPR19B" type="song"
> </song>
</Songs>
<producersMixersSongwritersEngineers>
<producers> Dave Cobb & Shooter Jennings </producers>
<engineersMixers> Dave Cobb & Eddie Spear
</engineersMixers>
<songwriters> Brandi Carlile, Phil Hanseroth & Tim
Hanseroth </songwriters>
<masteringEngineer> Pete Lyman </masteringEngineer>
</producersMixersSongwritersEngineers>
</album>
</artist>
架构代码:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="personorgroup" type="xs:string"> </xs:element>
<xs:element name="groupmembernames" type="xs:string"> </xs:element>
<xs:element name="artistorgroupcountry" type="xs:string">
</xs:element>
<xs:element name="careerBegin" type="xs:string"> </xs:element>
<xs:element name="careerend" type="xs:string"> </xs:element>
<xs:element name="artistName" type="xs:string"> </xs:element>
<xs:element name="genre" type="xs:string"> </xs:element>
<xs:element name="artist">
<xs:complexType>
<xs:sequence>
<xs:element ref="artist">
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
对于您的XML示例,以下架构将对其进行描述
<?xml version="1.0" encoding="utf-16"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Albums">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="artist">
<xs:complexType>
<xs:sequence>
<xs:element name="album">
<xs:complexType>
<xs:sequence>
<xs:element name="Comment" type="xs:string" />
<xs:element name="Rating" type="xs:string" />
<xs:element name="albumArt" type="xs:string" />
<xs:element name="releases">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="release">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="release" type="xs:string" use="required" />
<xs:attribute name="releasedate" type="xs:string" use="required" />
<xs:attribute name="recordlabel" type="xs:string" use="required" />
<xs:attribute name="recordlabelcatalognumber" type="xs:string" use="required" />
<xs:attribute name="barcodenumber" type="xs:unsignedLong" use="required" />
<xs:attribute name="country" type="xs:string" use="required" />
<xs:attribute name="format" type="xs:string" use="required" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Songs">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="song">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="songposition" type="xs:unsignedByte" use="required" />
<xs:attribute name="songlength" type="xs:string" use="required" />
<xs:attribute name="songcomposersandwriters" type="xs:string" use="required" />
<xs:attribute name="songName" type="xs:string" use="required" />
<xs:attribute name="sku" type="xs:string" use="required" />
<xs:attribute name="albumref" type="xs:string" use="required" />
<xs:attribute name="type" type="xs:string" use="required" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="producersMixersSongwritersEngineers">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="producers" type="xs:string" />
<xs:element name="engineersMixers" type="xs:string" />
<xs:element name="songwriters" type="xs:string" />
<xs:element name="masteringEngineer" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="albumCategory" type="xs:string" use="required" />
<xs:attribute name="albumName" type="xs:string" use="required" />
<xs:attribute name="sku" type="xs:string" use="required" />
<xs:attribute name="type" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="personorgroup" type="xs:string" use="required" />
<xs:attribute name="groupmembernames" type="xs:string" use="required" />
<xs:attribute name="artistorgroupcountry" type="xs:string" use="required" />
<xs:attribute name="careerBegin" type="xs:unsignedShort" use="required" />
<xs:attribute name="careerend" type="xs:string" use="required" />
<xs:attribute name="artistName" type="xs:string" use="required" />
<xs:attribute name="genre" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
但是,这与艺术家或团体以及团体成员的要求不符
为此您需要更多类似于下面的内容,您可以在其中拥有艺术家或组的记录,并且在组中您有一个可以多次出现的memberName元素。
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns:b="http://schemas.microsoft.com/BizTalk/2003" attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Albums">
<xs:complexType>
<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="artist">
<xs:complexType>
<xs:sequence>
<xs:element name="album" type="AlbumType" />
</xs:sequence>
<xs:attribute name="artistName" type="xs:string" use="required" />
<xs:attribute name="artistcountry" type="xs:string" use="required" />
<xs:attribute name="careerBegin" type="xs:unsignedShort" use="required" />
<xs:attribute name="careerend" type="xs:string" use="required" />
<xs:attribute name="genre" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
<xs:element name="group">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="memberName" type="xs:string" />
<xs:element name="album" type="AlbumType" />
</xs:sequence>
<xs:attribute name="artistName" type="xs:string" use="required" />
<xs:attribute name="groupBegin" type="xs:unsignedShort" use="required" />
<xs:attribute name="groupEnd" type="xs:string" use="required" />
<xs:attribute name="genre" type="xs:string" use="required" />
<xs:attribute name="groupcountry" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="AlbumType">
<xs:sequence maxOccurs="unbounded">
<xs:element name="Comment" type="xs:string" />
<xs:element name="Rating" type="xs:string" />
<xs:element name="albumArt" type="xs:string" />
<xs:element name="releases">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="release">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="release" type="xs:string" use="required" />
<xs:attribute name="releasedate" type="xs:string" use="required" />
<xs:attribute name="recordlabel" type="xs:string" use="required" />
<xs:attribute name="recordlabelcatalognumber" type="xs:string" use="required" />
<xs:attribute name="barcodenumber" type="xs:unsignedLong" use="required" />
<xs:attribute name="country" type="xs:string" use="required" />
<xs:attribute name="format" type="xs:string" use="required" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Songs">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="song">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="songposition" type="xs:unsignedByte" use="required" />
<xs:attribute name="songlength" type="xs:string" use="required" />
<xs:attribute name="songcomposersandwriters" type="xs:string" use="required" />
<xs:attribute name="songName" type="xs:string" use="required" />
<xs:attribute name="sku" type="xs:string" use="required" />
<xs:attribute name="albumref" type="xs:string" use="required" />
<xs:attribute name="type" type="xs:string" use="required" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="producersMixersSongwritersEngineers">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="producers" type="xs:string" />
<xs:element name="engineersMixers" type="xs:string" />
<xs:element name="songwriters" type="xs:string" />
<xs:element name="masteringEngineer" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="albumCategory" type="xs:string" use="required" />
<xs:attribute name="albumName" type="xs:string" use="required" />
<xs:attribute name="sku" type="xs:string" use="required" />
<xs:attribute name="type" type="xs:string" use="required" />
</xs:complexType>
</xs:schema>