XML文件外部写法--引入DTD规范

pet.dtd



<!ELEMENT pets (dogs,penguins)>

<!ELEMENT dogs (dog*)>

<!ATTLIST dog id CDATA #REQUIRED>

<!ELEMENT dog (health,love,decHealth,incLove)>

<!ELEMENT penguins (penguin*)>

<!ATTLIST penguin id CDATA #REQUIRED>

<!ELEMENT penguin (health,love,decHealth,incLove)>

<!ELEMENT health (#PCDATA)>

<!ELEMENT love (#PCDATA)>

<!ELEMENT decHealth (#PCDATA)>

<!ELEMENT inclove (#PCDATA)>



XML.xml



<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE pets SYSTEM "pet.dtd" >

<pet>

  <dogs>

	  <dog id="1">

		<health>100</health>

		<love>0</love>

		<decHealth>18</decHealth>

		<incLove>10</incLove>

	  </dog>

  </dogs>

	<dogs>

	  <dog id="2">

		<health>100</health>

		<love>0</love>

		<decHealth>18</decHealth>

		<incLove>10</incLove>

	  </dog>

	</dogs>

	<dogs>

	  <dog id="3">

		<health>100</health>

		<love>0</love>

		<decHealth>28</decHealth>

		<incLove>30</incLove>

	  </dog>

	</dogs>

	<penguins>

	  <penguin id="4">

		<health>100</health>

		<love>0</love>

		<decHealth>15</decHealth>

		<incLove>8</incLove>

	  </penguin>

	</penguins>

</pet>

  

你可能感兴趣的:(xml)