Pregunta

I am trying to learn XML and DTD , I just went through w3c tutorial for DTD, and trying to implement a recipe scenario in XML using DTD, this is what wrote in the DTD file:

<?xml version="1.0" encoding="UTF-8"?>
<!ENTITY  RECIPE (NAME,INGREDIENTS,INSTRUCTIONS) >
<!ENTITY NAME ("Baking Powder Biscuits") >
<!ENTITY  INGREDIENTS SYSTEM "Ingredients.dtd"  >
<!ENTITY  INSTRUCTIONS SYSTEM "Instructions.dtd" >

<!ATTLIST RECIPE UNITS "16 BISCUITS" #FIXED> 

When I try to verify ,the parses gives me a error in line 2 saying open quot missing in decl,can't undesrstand whats wrong, please help.

Thanks

This is xml file 'recipe':

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE RECIPE SYSTEM "recipe.dtd">

This is recipe dtd

<?xml version="1.0" encoding="UTF-8"?>
<!ENTITY  RECIPE NAME INGREDIENTS,INSTRUCTIONS>
<!ENTITY NAME "Baking Powder Biscuits" >
<!ENTITY  % INGREDIENTS SYSTEM "Ingredients.dtd"  >
<!ENTITY  % INSTRUCTIONS SYSTEM "Instructions.dtd" >

<!ATTLIST RECIPE UNITS CDATA #FIXED "16 BISCUITS" >

this is other dtd ingreduents:

<?xml version="1.0" encoding="UTF-8"?>
<!ENTITY  INGREDIENTS  ("2 cups flour","1 tablespoon sugar", "1/2 teaspoon salt", "1/2 cup vegetable shortening", "4 teaspoon baking powder", "2/3 cup milk")>
¿Fue útil?

Solución

You have an ENTITY declaration for RECIPE, but it looks like it should be an ELEMENT declaration (based on the model and the ATTLIST for RECIPE):

<!ELEMENT RECIPE (NAME,INGREDIENTS,INSTRUCTIONS) >

The NAME ENTITY declaration looks like it really should be an ENTITY, but you need to remove the parentheses:

<!ENTITY NAME "Baking Powder Biscuits">

Also, the two ENTITY declarations that point to the .dtd files should be parameter entities if they actually contain additional declarations:

<!ENTITY % INGREDIENTS SYSTEM "Ingredients.dtd"  >
<!ENTITY % INSTRUCTIONS SYSTEM "Instructions.dtd" >

You would reference them with %INGREDIENTS; and %INSTRUCTIONS;.

The ATTLIST for RECIPE is also incorrect. For a fixed value, try this:

<!ATTLIST RECIPE UNITS CDATA #FIXED "16 BISCUITS">

Otros consejos

Your document type definition files are not XML document instances; they should not begin with XML declarations. Once you delete the XML declarations from them, you will run into the problems identified by Daniel Haley.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top