xml - Why does DTD validation fail when optional child element is omitted? -
the xml document has embedded dtd declaration , fails.
here dtd:
<!doctype movielist [ <!element movielist (movie+)> <!element movie (title+, rating+, runtime+, genrelist*, datereleased+, country+, review+, description+, director+)> <!element title (#pcdata)> <!element rating (#pcdata)> <!element runtime (#pcdata)> <!element genrelist (genre+)> <!element genre (#pcdata)> <!element datereleased (#pcdata)> <!element country (#pcdata)> <!element review (#pcdata)> <!element description (#pcdata)> <!element director (#pcdata)> ]>
and here xml elements:
<movielist> <movie> <title>jaws</title> <rating>pg</rating> <runtime>124 minutes</runtime> <genrelist> <genre>adventure</genre> <genre>thriller</genre> </genrelist> <datereleased>20 june 1975</datereleased> <country>usa</country> <review>8</review> <description>when gigantic great white shark begins menace small island community of amity, police chief, marine scientist , grizzled fisherman set out stop it.</description> <director>steven spielberg</director> </movie> <movie> <title>the good, bad , ugly</title> <rating>nr</rating> <runtime>161 minutes</runtime> <genre>western</genre> <datereleased>23 december 1966</datereleased> <country>italy</country> <review>9</review> <description>a bounty hunting scam joins 2 men in uneasy alliance against third in race find fortune in gold buried in remote cemetery.</description> <director>sergio leone</director> </movie> </movielist>
it fails have 1 genre
, not wrapped elements genrelist
. should work because in movie
element declaration have genrelist*
means, genrelist
appear 0 or more.
you explain results , expectations well.
you're right genrelist*
means genrelist
may absent. however, if genrelist
absent, children cannot present. content model movie
has no provision genre
without genrelist
, xml invalid per dtd, reported correctly.
Comments
Post a Comment