aspose file tools*
The moose likes XML and Related Technologies and the fly likes DTD - XML noob question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "DTD - XML noob question" Watch "DTD - XML noob question" New topic
Author

DTD - XML noob question

Hernan Blanco
Greenhorn

Joined: Aug 23, 2010
Posts: 28
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
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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

Joined: Aug 23, 2010
Posts: 28
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
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Then at this point I would start reading the error messages, to see what they were trying to tell me.
Hernan Blanco
Greenhorn

Joined: Aug 23, 2010
Posts: 28
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
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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

Joined: Aug 23, 2010
Posts: 28
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

Joined: Apr 16, 2008
Posts: 2187


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

Joined: Aug 23, 2010
Posts: 28
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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DTD - XML noob question