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
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>
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.
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>
精彩评论