XML Context free grammar

mredfelix used Ask the Experts™
I want to know how to describe XML in the form of a Grammar.  I am not sure if it is a COntext free Grammar or a meta Grammar.  I need to know the specfication for an XMl Context free gammar.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Go and fetch the document http://www.w3.org/TR/REC-xml and extract the syntax rules like :-

[45]    elementdecl    ::=    '<!ELEMENT' S Name S contentspec S? '>' [VC: Unique Element Type Declaration]
[46]    contentspec    ::=    'EMPTY' | 'ANY' | Mixed | children  

and voilà! you have a grammar for XML.



can u explaine to me the termnology of the examples u have given me so i can learn how to read them
The quoted strings (eg: 'EMPTY') are literals. That means that the text inside the string MUST appear in the source.

A question mark behind a quoted string or a name means that the thing may appear or not, ie: option.

The vertical bar separates alternatives, that is to say in

     A | B | C

an A or a B or a C may appear - at least one of them.

Things in brackets, line the [45] above are just comments and may be ignored.

Things without any separation like '<!ELEMENT' S Name S contentspec S? '>' means that they appear in sequence, ie: one after each other.

Lastly the names like contentspec. These define rules which may be recursively applied. The names are called production names. Some people also call them meta-names.

The rule, here number 46,

   contentspec =  'EMPTY' | 'ANY' | Mixed | children  


   contentspec is either the literal string EMPTY, or the literal string ANY or the production Mixed or the production children.

The rule elementdecl reads

    elementdecl consists of the literal string <!ELEMENT, followed by the production S (which is actually defines whitespace) (and ín this case MUST be there), followed by the production Name, followed by the production S, followed by the production contentspec, optionally (due to the question mark) followed by the production S, followed by the literal string >.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial