• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DTD - XML noob question

 
Hernan Blanco
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi! I'm a beginner about XML and DTD... I'm trying to design a films catalog, but I'm getting an error when I do something like that:



Validators throws an error when I put a PCDATA as child of an element containing more than one children (e.g. tagOne). Why is happening that, and how can I resolve it?

PS: I know that's not the best way to do an XML file (putting a PCDATA child into an element containing more children), but I'm not the responsable about that specification!

Thanks in advance.
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not very good with DTD either, so could you explain why you used "PCDATA" in one place and "#PCDATA" in the other places? Do they mean different things?
 
Hernan Blanco
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:I'm not very good with DTD either, so could you explain why you used "PCDATA" in one place and "#PCDATA" in the other places? Do they mean different things?


I'm not sure... At first, I've used #PCDATA? but validators threw an error at the DTD, then I tried changing that and validators didn't throw DTD errors... but yes XML errors.
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then at this point I would start reading the error messages, to see what they were trying to tell me.
 
Hernan Blanco
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Error at 12:10 The content of element type "tagOne" must match "(tagTwo,PCDATA?,tagThree)".

The error isn't very explicit. Another validator throws:

Element tagOne content does not follow the DTD, expecting (tagTwo , PCDATA? , tagThree), got (tagTwo CDATA tagThree )
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you are trying to describe with your DTD there is called "mixed content" -- that means mixing elements and text together. So I googled "DTD mixed content" and I found this page, which says
The mixed content model can only specify the names of child elements that can occur. A child elements order or number of occurrences cannot be set. Having these limitations it is not recommended to use the mixed content model. In most circumstances it is better to declare a new element that can hold PCDATA.


And I found this document, which says
Note that in XML DTD, 'Mixed' content model does not
define order of child elements, does not specify how many
times child element may be repeated in markup, and can not
be combined with other content models.
 
Hernan Blanco
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, as I said before, I know that it's not a good practice, but I didn't create the XML specification (he was my professor...), so I have to create the DTD rules that specifies the XML he gave me.

I had used the mixed content model in some cases, but it can be used when applying an 'or' rule at the DTD, and it isn't the case. However, reading the pages you gave me, I had an idea, doing that:



But I still getting an error. So I tried deleting the tagTwo tag:



and also deleting it from the xml:



And it worked fine. So, I realized that you can't nest the mixed content like I tried before. Beacause this, it isn't a good practice, using the mixed content model: you lose quite a lot of semantic information about the document.

Thank you so much!
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This declaration includes a "mixed content model" and is an example of poor language design. Element definitions should specify either child elements or text data, but not both. An occurence indicator on a model containing #PCDATA is not logical.
 
Hernan Blanco
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I agree with you Jimmy. But, quoting myself, I said that:

PS: I know that's not the best way to do an XML file (putting a PCDATA child into an element containing more children), but I'm not the responsable about that specification!


Yes, as I said before, I know that it's not a good practice, but I didn't create the XML specification (he was my professor...), so I have to create the DTD rules that specifies the XML he gave me.


... Beacause this, it isn't a good practice, using the mixed content model: you lose quite a lot of semantic information about the document.


Thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic