atom.rng 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. -*- rnc -*-
  4. RELAX NG Compact Syntax Grammar for the
  5. Atom Format Specification Version 11
  6. -->
  7. <grammar ns="http://www.w3.org/1999/xhtml" xmlns:s="http://www.ascc.net/xml/schematron" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
  8. <start>
  9. <choice>
  10. <ref name="atomFeed"/>
  11. <ref name="atomEntry"/>
  12. </choice>
  13. </start>
  14. <!-- Common attributes -->
  15. <define name="atomCommonAttributes">
  16. <optional>
  17. <attribute name="xml:base">
  18. <ref name="atomUri"/>
  19. </attribute>
  20. </optional>
  21. <optional>
  22. <attribute name="xml:lang">
  23. <ref name="atomLanguageTag"/>
  24. </attribute>
  25. </optional>
  26. <zeroOrMore>
  27. <ref name="undefinedAttribute"/>
  28. </zeroOrMore>
  29. </define>
  30. <!-- Text Constructs -->
  31. <define name="atomPlainTextConstruct">
  32. <ref name="atomCommonAttributes"/>
  33. <optional>
  34. <attribute name="type">
  35. <choice>
  36. <value>text</value>
  37. <value>html</value>
  38. </choice>
  39. </attribute>
  40. </optional>
  41. <text/>
  42. </define>
  43. <define name="atomXHTMLTextConstruct">
  44. <ref name="atomCommonAttributes"/>
  45. <attribute name="type">
  46. <value>xhtml</value>
  47. </attribute>
  48. <ref name="xhtmlDiv"/>
  49. </define>
  50. <define name="atomTextConstruct">
  51. <choice>
  52. <ref name="atomPlainTextConstruct"/>
  53. <ref name="atomXHTMLTextConstruct"/>
  54. </choice>
  55. </define>
  56. <!-- Person Construct -->
  57. <define name="atomPersonConstruct">
  58. <ref name="atomCommonAttributes"/>
  59. <interleave>
  60. <element name="atom:name">
  61. <text/>
  62. </element>
  63. <optional>
  64. <element name="atom:uri">
  65. <ref name="atomUri"/>
  66. </element>
  67. </optional>
  68. <optional>
  69. <element name="atom:email">
  70. <ref name="atomEmailAddress"/>
  71. </element>
  72. </optional>
  73. <zeroOrMore>
  74. <ref name="extensionElement"/>
  75. </zeroOrMore>
  76. </interleave>
  77. </define>
  78. <!-- Date Construct -->
  79. <define name="atomDateConstruct">
  80. <ref name="atomCommonAttributes"/>
  81. <data type="dateTime"/>
  82. </define>
  83. <!-- atom:feed -->
  84. <define name="atomFeed">
  85. <element name="atom:feed">
  86. <s:rule context="atom:feed">
  87. <s:assert test="atom:author or not(atom:entry[not(atom:author)])">An atom:feed must have an atom:author unless all of its atom:entry children have an atom:author.</s:assert>
  88. </s:rule>
  89. <ref name="atomCommonAttributes"/>
  90. <interleave>
  91. <zeroOrMore>
  92. <ref name="atomAuthor"/>
  93. </zeroOrMore>
  94. <zeroOrMore>
  95. <ref name="atomCategory"/>
  96. </zeroOrMore>
  97. <zeroOrMore>
  98. <ref name="atomContributor"/>
  99. </zeroOrMore>
  100. <optional>
  101. <ref name="atomGenerator"/>
  102. </optional>
  103. <optional>
  104. <ref name="atomIcon"/>
  105. </optional>
  106. <ref name="atomId"/>
  107. <zeroOrMore>
  108. <ref name="atomLink"/>
  109. </zeroOrMore>
  110. <optional>
  111. <ref name="atomLogo"/>
  112. </optional>
  113. <optional>
  114. <ref name="atomRights"/>
  115. </optional>
  116. <optional>
  117. <ref name="atomSubtitle"/>
  118. </optional>
  119. <ref name="atomTitle"/>
  120. <ref name="atomUpdated"/>
  121. <zeroOrMore>
  122. <ref name="extensionElement"/>
  123. </zeroOrMore>
  124. </interleave>
  125. <zeroOrMore>
  126. <ref name="atomEntry"/>
  127. </zeroOrMore>
  128. </element>
  129. </define>
  130. <!-- atom:entry -->
  131. <define name="atomEntry">
  132. <element name="atom:entry">
  133. <s:rule context="atom:entry">
  134. <s:assert test="atom:link[@rel='alternate'] or atom:link[not(@rel)] or atom:content">An atom:entry must have at least one atom:link element with a rel attribute of 'alternate' or an atom:content.</s:assert>
  135. </s:rule>
  136. <s:rule context="atom:entry">
  137. <s:assert test="atom:author or ../atom:author or atom:source/atom:author">An atom:entry must have an atom:author if its feed does not.</s:assert>
  138. </s:rule>
  139. <ref name="atomCommonAttributes"/>
  140. <interleave>
  141. <zeroOrMore>
  142. <ref name="atomAuthor"/>
  143. </zeroOrMore>
  144. <zeroOrMore>
  145. <ref name="atomCategory"/>
  146. </zeroOrMore>
  147. <optional>
  148. <ref name="atomContent"/>
  149. </optional>
  150. <zeroOrMore>
  151. <ref name="atomContributor"/>
  152. </zeroOrMore>
  153. <ref name="atomId"/>
  154. <zeroOrMore>
  155. <ref name="atomLink"/>
  156. </zeroOrMore>
  157. <optional>
  158. <ref name="atomPublished"/>
  159. </optional>
  160. <optional>
  161. <ref name="atomRights"/>
  162. </optional>
  163. <optional>
  164. <ref name="atomSource"/>
  165. </optional>
  166. <optional>
  167. <ref name="atomSummary"/>
  168. </optional>
  169. <ref name="atomTitle"/>
  170. <ref name="atomUpdated"/>
  171. <zeroOrMore>
  172. <ref name="extensionElement"/>
  173. </zeroOrMore>
  174. </interleave>
  175. </element>
  176. </define>
  177. <!-- atom:content -->
  178. <define name="atomInlineTextContent">
  179. <element name="atom:content">
  180. <ref name="atomCommonAttributes"/>
  181. <optional>
  182. <attribute name="type">
  183. <choice>
  184. <value>text</value>
  185. <value>html</value>
  186. </choice>
  187. </attribute>
  188. </optional>
  189. <zeroOrMore>
  190. <text/>
  191. </zeroOrMore>
  192. </element>
  193. </define>
  194. <define name="atomInlineXHTMLContent">
  195. <element name="atom:content">
  196. <ref name="atomCommonAttributes"/>
  197. <attribute name="type">
  198. <value>xhtml</value>
  199. </attribute>
  200. <ref name="xhtmlDiv"/>
  201. </element>
  202. </define>
  203. <define name="atomInlineOtherContent">
  204. <element name="atom:content">
  205. <ref name="atomCommonAttributes"/>
  206. <optional>
  207. <attribute name="type">
  208. <ref name="atomMediaType"/>
  209. </attribute>
  210. </optional>
  211. <zeroOrMore>
  212. <choice>
  213. <text/>
  214. <ref name="anyElement"/>
  215. </choice>
  216. </zeroOrMore>
  217. </element>
  218. </define>
  219. <define name="atomOutOfLineContent">
  220. <element name="atom:content">
  221. <ref name="atomCommonAttributes"/>
  222. <optional>
  223. <attribute name="type">
  224. <ref name="atomMediaType"/>
  225. </attribute>
  226. </optional>
  227. <attribute name="src">
  228. <ref name="atomUri"/>
  229. </attribute>
  230. <empty/>
  231. </element>
  232. </define>
  233. <define name="atomContent">
  234. <choice>
  235. <ref name="atomInlineTextContent"/>
  236. <ref name="atomInlineXHTMLContent"/>
  237. <ref name="atomInlineOtherContent"/>
  238. <ref name="atomOutOfLineContent"/>
  239. </choice>
  240. </define>
  241. <!-- atom:author -->
  242. <define name="atomAuthor">
  243. <element name="atom:author">
  244. <ref name="atomPersonConstruct"/>
  245. </element>
  246. </define>
  247. <!-- atom:category -->
  248. <define name="atomCategory">
  249. <element name="atom:category">
  250. <ref name="atomCommonAttributes"/>
  251. <attribute name="term"/>
  252. <optional>
  253. <attribute name="scheme">
  254. <ref name="atomUri"/>
  255. </attribute>
  256. </optional>
  257. <optional>
  258. <attribute name="label"/>
  259. </optional>
  260. <ref name="undefinedContent"/>
  261. </element>
  262. </define>
  263. <!-- atom:contributor -->
  264. <define name="atomContributor">
  265. <element name="atom:contributor">
  266. <ref name="atomPersonConstruct"/>
  267. </element>
  268. </define>
  269. <!-- atom:generator -->
  270. <define name="atomGenerator">
  271. <element name="atom:generator">
  272. <ref name="atomCommonAttributes"/>
  273. <optional>
  274. <attribute name="uri">
  275. <ref name="atomUri"/>
  276. </attribute>
  277. </optional>
  278. <optional>
  279. <attribute name="version"/>
  280. </optional>
  281. <text/>
  282. </element>
  283. </define>
  284. <!-- atom:icon -->
  285. <define name="atomIcon">
  286. <element name="atom:icon">
  287. <ref name="atomCommonAttributes"/>
  288. <ref name="atomUri"/>
  289. </element>
  290. </define>
  291. <!-- atom:id -->
  292. <define name="atomId">
  293. <element name="atom:id">
  294. <ref name="atomCommonAttributes"/>
  295. <ref name="atomUri"/>
  296. </element>
  297. </define>
  298. <!-- atom:logo -->
  299. <define name="atomLogo">
  300. <element name="atom:logo">
  301. <ref name="atomCommonAttributes"/>
  302. <ref name="atomUri"/>
  303. </element>
  304. </define>
  305. <!-- atom:link -->
  306. <define name="atomLink">
  307. <element name="atom:link">
  308. <ref name="atomCommonAttributes"/>
  309. <attribute name="href">
  310. <ref name="atomUri"/>
  311. </attribute>
  312. <optional>
  313. <attribute name="rel">
  314. <choice>
  315. <ref name="atomNCName"/>
  316. <ref name="atomUri"/>
  317. </choice>
  318. </attribute>
  319. </optional>
  320. <optional>
  321. <attribute name="type">
  322. <ref name="atomMediaType"/>
  323. </attribute>
  324. </optional>
  325. <optional>
  326. <attribute name="hreflang">
  327. <ref name="atomLanguageTag"/>
  328. </attribute>
  329. </optional>
  330. <optional>
  331. <attribute name="title"/>
  332. </optional>
  333. <optional>
  334. <attribute name="length"/>
  335. </optional>
  336. <ref name="undefinedContent"/>
  337. </element>
  338. </define>
  339. <!-- atom:published -->
  340. <define name="atomPublished">
  341. <element name="atom:published">
  342. <ref name="atomDateConstruct"/>
  343. </element>
  344. </define>
  345. <!-- atom:rights -->
  346. <define name="atomRights">
  347. <element name="atom:rights">
  348. <ref name="atomTextConstruct"/>
  349. </element>
  350. </define>
  351. <!-- atom:source -->
  352. <define name="atomSource">
  353. <element name="atom:source">
  354. <ref name="atomCommonAttributes"/>
  355. <interleave>
  356. <zeroOrMore>
  357. <ref name="atomAuthor"/>
  358. </zeroOrMore>
  359. <zeroOrMore>
  360. <ref name="atomCategory"/>
  361. </zeroOrMore>
  362. <zeroOrMore>
  363. <ref name="atomContributor"/>
  364. </zeroOrMore>
  365. <optional>
  366. <ref name="atomGenerator"/>
  367. </optional>
  368. <optional>
  369. <ref name="atomIcon"/>
  370. </optional>
  371. <optional>
  372. <ref name="atomId"/>
  373. </optional>
  374. <zeroOrMore>
  375. <ref name="atomLink"/>
  376. </zeroOrMore>
  377. <optional>
  378. <ref name="atomLogo"/>
  379. </optional>
  380. <optional>
  381. <ref name="atomRights"/>
  382. </optional>
  383. <optional>
  384. <ref name="atomSubtitle"/>
  385. </optional>
  386. <optional>
  387. <ref name="atomTitle"/>
  388. </optional>
  389. <optional>
  390. <ref name="atomUpdated"/>
  391. </optional>
  392. <zeroOrMore>
  393. <ref name="extensionElement"/>
  394. </zeroOrMore>
  395. </interleave>
  396. </element>
  397. </define>
  398. <!-- atom:subtitle -->
  399. <define name="atomSubtitle">
  400. <element name="atom:subtitle">
  401. <ref name="atomTextConstruct"/>
  402. </element>
  403. </define>
  404. <!-- atom:summary -->
  405. <define name="atomSummary">
  406. <element name="atom:summary">
  407. <ref name="atomTextConstruct"/>
  408. </element>
  409. </define>
  410. <!-- atom:title -->
  411. <define name="atomTitle">
  412. <element name="atom:title">
  413. <ref name="atomTextConstruct"/>
  414. </element>
  415. </define>
  416. <!-- atom:updated -->
  417. <define name="atomUpdated">
  418. <element name="atom:updated">
  419. <ref name="atomDateConstruct"/>
  420. </element>
  421. </define>
  422. <!-- Low-level simple types -->
  423. <define name="atomNCName">
  424. <data type="string">
  425. <param name="minLength">1</param>
  426. <param name="pattern">[^:]*</param>
  427. </data>
  428. </define>
  429. <!-- Whatever a media type is, it contains at least one slash -->
  430. <define name="atomMediaType">
  431. <data type="string">
  432. <param name="pattern">.+/.+</param>
  433. </data>
  434. </define>
  435. <!-- As defined in RFC 3066 -->
  436. <define name="atomLanguageTag">
  437. <data type="string">
  438. <param name="pattern">[A-Za-z]{1,8}(-[A-Za-z0-9]{1,8})*</param>
  439. </data>
  440. </define>
  441. <!--
  442. Unconstrained; it's not entirely clear how IRI fit into
  443. xsd:anyURI so let's not try to constrain it here
  444. -->
  445. <define name="atomUri">
  446. <text/>
  447. </define>
  448. <!-- Whatever an email address is, it contains at least one @ -->
  449. <define name="atomEmailAddress">
  450. <data type="string">
  451. <param name="pattern">.+@.+</param>
  452. </data>
  453. </define>
  454. <!-- Simple Extension -->
  455. <define name="simpleExtensionElement">
  456. <element>
  457. <anyName>
  458. <except>
  459. <nsName ns="http://www.w3.org/2005/Atom"/>
  460. </except>
  461. </anyName>
  462. <text/>
  463. </element>
  464. </define>
  465. <!-- Structured Extension -->
  466. <define name="structuredExtensionElement">
  467. <element>
  468. <anyName>
  469. <except>
  470. <nsName ns="http://www.w3.org/2005/Atom"/>
  471. </except>
  472. </anyName>
  473. <choice>
  474. <group>
  475. <oneOrMore>
  476. <attribute>
  477. <anyName/>
  478. </attribute>
  479. </oneOrMore>
  480. <zeroOrMore>
  481. <choice>
  482. <text/>
  483. <ref name="anyElement"/>
  484. </choice>
  485. </zeroOrMore>
  486. </group>
  487. <group>
  488. <zeroOrMore>
  489. <attribute>
  490. <anyName/>
  491. </attribute>
  492. </zeroOrMore>
  493. <group>
  494. <optional>
  495. <text/>
  496. </optional>
  497. <oneOrMore>
  498. <ref name="anyElement"/>
  499. </oneOrMore>
  500. <zeroOrMore>
  501. <choice>
  502. <text/>
  503. <ref name="anyElement"/>
  504. </choice>
  505. </zeroOrMore>
  506. </group>
  507. </group>
  508. </choice>
  509. </element>
  510. </define>
  511. <!-- Other Extensibility -->
  512. <define name="extensionElement">
  513. <choice>
  514. <ref name="simpleExtensionElement"/>
  515. <ref name="structuredExtensionElement"/>
  516. </choice>
  517. </define>
  518. <define name="undefinedAttribute">
  519. <attribute>
  520. <anyName>
  521. <except>
  522. <name>xml:base</name>
  523. <name>xml:lang</name>
  524. <nsName ns=""/>
  525. </except>
  526. </anyName>
  527. </attribute>
  528. </define>
  529. <define name="undefinedContent">
  530. <zeroOrMore>
  531. <choice>
  532. <text/>
  533. <ref name="anyForeignElement"/>
  534. </choice>
  535. </zeroOrMore>
  536. </define>
  537. <define name="anyElement">
  538. <element>
  539. <anyName/>
  540. <zeroOrMore>
  541. <choice>
  542. <attribute>
  543. <anyName/>
  544. </attribute>
  545. <text/>
  546. <ref name="anyElement"/>
  547. </choice>
  548. </zeroOrMore>
  549. </element>
  550. </define>
  551. <define name="anyForeignElement">
  552. <element>
  553. <anyName>
  554. <except>
  555. <nsName ns="http://www.w3.org/2005/Atom"/>
  556. </except>
  557. </anyName>
  558. <zeroOrMore>
  559. <choice>
  560. <attribute>
  561. <anyName/>
  562. </attribute>
  563. <text/>
  564. <ref name="anyElement"/>
  565. </choice>
  566. </zeroOrMore>
  567. </element>
  568. </define>
  569. <!-- XHTML -->
  570. <define name="anyXHTML">
  571. <element>
  572. <nsName/>
  573. <zeroOrMore>
  574. <choice>
  575. <attribute>
  576. <anyName/>
  577. </attribute>
  578. <text/>
  579. <ref name="anyXHTML"/>
  580. </choice>
  581. </zeroOrMore>
  582. </element>
  583. </define>
  584. <define name="xhtmlDiv">
  585. <element name="xhtml:div">
  586. <zeroOrMore>
  587. <choice>
  588. <attribute>
  589. <anyName/>
  590. </attribute>
  591. <text/>
  592. <ref name="anyXHTML"/>
  593. </choice>
  594. </zeroOrMore>
  595. </element>
  596. </define>
  597. </grammar>