-1

can you please tell how i can extend the following code so that five professions can be added in the xml document?

<?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>
        <first_name>Jack</first_name>
        <last_name>Jill</last_name>
    </name>
    <profession>website</profession>
</person>

thanks for answering

Selom
  • 729
  • 8
  • 15
  • 21

3 Answers3

3

Something like this should do

<?xml version=”1.0” encoding=”ISO-8859”?>
<!DOCTYPE person [
    <!ELEMENT first_name ( #PCDATA ) >
    <!ELEMENT last_name ( #PCDATA ) >
    <!ELEMENT name ( first_name, last_name ) >
    <!ELEMENT person ( name, professions ) >
    <!ELEMENT profession ( #PCDATA ) >
    <!ELEMENT professions ( profession+ ) >
]>
<person>
    <name>
        <first_name>Jack</first_name>
        <last_name>Jill</last_name>
    </name>
    <professions>
        <profession>website</profession>
        <profession>some other profession</profession>
    </professions>
</person>
Marek Karbarz
  • 28,956
  • 6
  • 53
  • 73
  • Are you still grabbing the 'name' and 'person' elements that he is asking about? – Chris Nov 19 '09 at 21:00
  • I think the problem is with the embedded DTD-type spec at the top of the document, which allows only one profession element per person element. – Larry Lustig Nov 19 '09 at 21:02
  • I failed to update the DTD - but this update one should be fine – Marek Karbarz Nov 19 '09 at 21:04
  • thanks, it works. how can i modify the code so that one or zero address can be added in the xml code? the one showed me was about one or many. thanks for replying – Selom Nov 19 '09 at 21:37
1

The DTD at the top of the document specifies one name and one profession per person element.

Change it to use + (if you want one or more professions) or * (if you want 0 or more professions):

<!ELEMENT person (name, profession+)

or

<!ELEMENT person (name, profession*)

Note that DTDs are rather out-of-fashion, generally replaced by XSD specifications, which are more flexible and written in XML themselves.

Larry Lustig
  • 49,320
  • 14
  • 110
  • 160
  • thanks, it works. how can i modify the code so that one or zero address can be added in the xml code? the one showed me was about one or many. thanks for replying – Selom Nov 19 '09 at 21:34
1

Change the DTD to

<?xml version=”1.0” encoding=”ISO-8859”?>
<!DOCTYPE person [
<!ELEMENT first_name (#PCDATA)>
<!ELEMENT last_name (#PCDATA)>
<!ELEMENT profession (#PCDATA)>
<!ELEMENT professions (profession*)>
<!ELEMENT name (first_name, last_name)>
<!ELEMENT person (name, professions)>]>
<person>
<name>
<first_name>Jack</first_name>
<last_name>Jill</last_name>
</name>
<professions>
    <profession>prof 1</profession>
    <profession>prof 2</profession>
</professions>
</person>
tranmq
  • 15,168
  • 3
  • 31
  • 27
  • thanks, it works. how can i modify the code so that one or zero address can be added in the xml code? the one showed me was about one or many. thanks for replying – Selom Nov 19 '09 at 21:35