-1

I'm quite new to XML, can someone tell me what exactly this code is supposed to do?

<?xml version="1.0" encoding="ISO-8859"?> 
<!DOCTYPE person [ 
    <!ELEMENT first_name(#PCDATA)>
    <!ELEMENT last_name(#PCDATA)>
    <!ELEMENT PROFESSION(#PCDATA)>
    <!ELEMENT name(first_name, last_name)>
    <!ELEMENT person (name, profession)>]> 
<person>
    <name>
        <last_name>Jack</last_name>
        <last_name>Jill</last_name> 
    </name>
</person>
Simon B.
  • 2,530
  • 24
  • 30
Selom
  • 729
  • 8
  • 15
  • 21

3 Answers3

8

That is an XML file, and it doesn't do anything by itself. Instead, it appears to define a "person" with two last names (but the file is invalid because the DTD indicates both first name and last name).

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
4

That's an embedded DTD, which dictates which elements are permitted in which order, e.g. the "name" element must contain first_name followed by last_name.

It's an unconventional approach, but should be valid. Normally the DTD is an external file, rather than being embedded in the source document.

skaffman
  • 398,947
  • 96
  • 818
  • 769
  • hi and thanks again, it is me again. please what should be the changes to be made for the code to run without error.thanks – Selom Nov 12 '09 at 23:07
  • You don't "run" an XML document. You haven't told us what your problem is, either. – skaffman Nov 13 '09 at 08:37
  • thanks for replying. can we say the code above is well-formed and why? thanks for replying. – Selom Nov 17 '09 at 01:03
1

The xml document first indicates that it's an xml document by having a prolog ( <?xml ). An optional DOCTYPE is defined, this basically just is a list of all possible elements and attributes in the document, and lastly the actual document itself is defined with person being the root node, name being the first child, having two children which are last_name nodes.

I think the first node under name should be first_name, not last_name.

meder omuraliev
  • 183,342
  • 71
  • 393
  • 434