Skip to content

“Are element declarations for an xml document to be inserted in the xml document itself?

When I add the following line:
<!ELEMENT book(category,title,author)>
into the xml document at the top the parser complains that the
xml document is not well formed.
Any advice?

One Comment

  1. richarduie wrote:

    Probably, you’ve omitted the <!DOCTYPE declaration to wrap your <!ELEMENT declaration.

    The declarations of the elements don’t have to but should be composed in another file. I say "should be composed in another file," because you generally expect to create more than one document of a particular type; you don’t have to copy/paste the type definitions into every instance of the XML type; changes to the XML type need only be made in one place. Document Type Definitions or Schemas are used to define the elements. An XML document declares that it conforms to the definitions of that external file.

    Schemas are becoming the preferred approach:

    http://www.ibm.com/developerworks/xml/library/x-sbsch.html

    If you just gotta put the definitions into the implementing document, here’s a simple intro to inline DTD specifications:

    http://www.w3schools.com/DTD/dtd_intro.asp

    Friday, December 18, 2009 at 11:22 pm | Permalink

Post a Comment

Your email is never published nor shared.