2017-04-12 2 views
1

Je travaille sur une mission et j'ai obtenu mon résultat, mais il m'a semblé que j'avais oublié de déclarer les éléments dans mon fichier DTD. Est-ce que je déclare tous les éléments ou seulement les éléments avec des informations supplémentaires? Si je ne suis pas clair, voici un extrait de ma mission:Comment déclarer des éléments DTD?

<entry id= 'c01'> 
<MetaTags>Business</MetaTags> 
<title><brand>HP Pavilion</brand><name>550-112NA</name></title> 
<Desciption>While other towers have been standing still, HP has revolutionized the category. From magnified performance and reliability, to its stylish redesign, this HP Pavilion is the best thing to happen to towers in over 20 years.</Desciption> 
<Price>€579</Price> 
<Image src ="Image1.jpg"/> 
<Specs> 
    <CPU>A10-8750 APU</CPU> 
    <GPU>Radeon R7</GPU> 
    <RAM>8 GB DDR3</RAM> 
    <Storage><HDD> 2TB </HDD><SSD></SSD></Storage> 
    <OS>Windows 10</OS> 
    <optional> 
     <Monitor>LG 22" Full HD TV</Monitor> 
     <Keyboard>Microsoft Wired Keyboard 600</Keyboard> 
     <Mouse>Logitech M705 Mouse</Mouse>    
     </optional> 
    </Specs> 
</entry> 

Est-ce que l'entrée de l'étiquette doit être déclarée, mais pas d'autres éléments seraient parce qu'ils ne disposent pas d'autres variables?

Si c'est exact, la déclaration serait ressembler à ceci:

<!ATTLIST entry id CDATA #REQUIRED> 

J'espère que je fais ma question est claire, comme je suis nouveau à mon DTD XML.Here si vous avez besoin de voir que, et si je fais quelque chose d'autre qui ne va pas. Merci!

<!ELEMENT ComputerShop (entry+)> 
<!ELEMENT entry (MetaTags, title, Description, Price, Image, Specs)> 
<!ELEMENT MetaTags (#PCDATA)> 
<!ELEMENT Description (#PCDATA)> 
<!ELEMENT Price (#PCDATA)> 
<!ELEMENT Image (#PCDATA)> 
<!ELEMENT title (brand, name)> 
<!ELEMENT brand (#PCDATA)> 
<!ELEMENT name (#PCDATA)> 
<!ELEMENT Specs (CPU, GPU, RAM, Storage, OS, optional)> 
<!ELEMENT CPU (#PCDATA)> 
<!ELEMENT GPU (#PCDATA)> 
<!ELEMENT RAM (#PCDATA)> 
<!ELEMENT Storage (HDD | SSD)> 
<!ELEMENT OS (#PCDATA)> 
<!ELEMENT optional (Monitor | Keyboard | Mouse> 
<!ELEMENT Monitor (#PCDATA)> 
<!ELEMENT Keyboard (#PCDATA)> 
<!ELEMENT Mouse (#PCDATA)> 

Merci!

Répondre

1

... J'ai oublié de déclarer les éléments dans mon fichier DTD

Je pense que vous voulez dire «j'ai oublié de déclarer les attributs dans mon fichier DTD ».

Tous les attributs (les "informations supplémentaires" sur les éléments) doivent être déclarés.

Vous devez donc déclarer l'attribut id sur l'élément entry et l'attribut src sur l'élément Image.

Voici d'autres modifications que vous devez faire ...

DTD Changements

  • paren fermeture manquants dans <!ELEMENT Specs (CPU, GPU, RAM, Storage, OS, optional)>

  • Declare éléments HDD et SSD: <!ELEMENT HDD (#PCDATA)> et <!ELEMENT SDD (#PCDATA)>

  • La déclaration de optional doit être modifiée. Peut-être à <!ELEMENT optional (Monitor | Keyboard | Mouse)*> (zéro ou plusieurs occurrences de moniteur, clavier ou souris (dans n'importe quel ordre)) ou à <!ELEMENT optional (Monitor?, Keyboard?, Mouse?)> (zéro ou un moniteur suivi de zéro ou un clavier suivi de zéro ou une souris).

XML Changements

  • Description mal orthographié comme Desciption.

  • Le contenu de Storage est un HDD ou un SSD; pas les deux. Retirez le vide <SSD></SSD>.

Voici les fichiers corrigés ...

DTD

<!ELEMENT ComputerShop (entry+)> 
<!ELEMENT entry (MetaTags, title, Description, Price, Image, Specs)> 
<!ATTLIST entry id CDATA #REQUIRED> 
<!ELEMENT MetaTags (#PCDATA)> 
<!ELEMENT Description (#PCDATA)> 
<!ELEMENT Price (#PCDATA)> 
<!ELEMENT Image (#PCDATA)> 
<!ATTLIST Image src CDATA #REQUIRED> 
<!ELEMENT title (brand, name)> 
<!ELEMENT brand (#PCDATA)> 
<!ELEMENT name (#PCDATA)> 
<!ELEMENT Specs (CPU, GPU, RAM, Storage, OS, optional)> 
<!ELEMENT CPU (#PCDATA)> 
<!ELEMENT GPU (#PCDATA)> 
<!ELEMENT RAM (#PCDATA)> 
<!ELEMENT Storage (HDD | SSD)> 
<!ELEMENT HDD (#PCDATA)> 
<!ELEMENT SDD (#PCDATA)> 
<!ELEMENT OS (#PCDATA)> 
<!ELEMENT optional (Monitor | Keyboard | Mouse)*> 
<!ELEMENT Monitor (#PCDATA)> 
<!ELEMENT Keyboard (#PCDATA)> 
<!ELEMENT Mouse (#PCDATA)> 

XML

<entry id='c01'> 
    <MetaTags>Business</MetaTags> 
    <title><brand>HP Pavilion</brand><name>550-112NA</name></title> 
    <Description>While other towers have been standing still, HP has revolutionized the category. From magnified performance and reliability, to its stylish redesign, this HP Pavilion is the best thing to happen to towers in over 20 years.</Description> 
    <Price>€579</Price> 
    <Image src="Image1.jpg"/> 
    <Specs> 
     <CPU>A10-8750 APU</CPU> 
     <GPU>Radeon R7</GPU> 
     <RAM>8 GB DDR3</RAM> 
     <Storage><HDD> 2TB </HDD></Storage> 
     <OS>Windows 10</OS> 
     <optional> 
      <Monitor>LG 22" Full HD TV</Monitor> 
      <Keyboard>Microsoft Wired Keyboard 600</Keyboard> 
      <Mouse>Logitech M705 Mouse</Mouse>    
     </optional> 
    </Specs> 
</entry>