tags:

views:

159

answers:

4

hi, im quite new to xml, can someone tell me what exactly this code is 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>
+7  A: 

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
+4  A: 

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
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
You don't "run" an XML document. You haven't told us what your problem is, either.
skaffman
thanks for replying. can we say the code above is well-formed and why? thanks for replying.
Selom
+1  A: 

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
A: 

thank you all. i have downloaded some books and im about to read them. once again thanks.

Selom