• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

mixed content

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<!Element root (#pcdata,c1,c2)*>
is this the xml for above dtd
<root>hello
<c1>how are u<c1>
<c2>welcome<c2>
good Job
<c2>grat</c2>
</root>
Can somebody expalin mixed content with eg?
How can I test the xml against my dtd ?
 
Vasudha Deepak
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The XML file is not for the DTD shown.Infact both the XML file and the DTD are not well formed.
The correct DTD would be as follows:
jranch.dtd
<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT root (#PCDATA | c1 | c2)*>
<!ELEMENT c1 (#PCDATA)>
<!ELEMENT c2 (#PCDATA)>
When mixed content is used,the separator between elements has to be | and #PCDATA should appear first in the list specified .

The correct XML would be:
jranch.xml
<?xml version="1.0"?>
<!DOCTYPE root SYSTEM "jranch.dtd">
<root>hello
<c1>how are u</c1>
<c2>welcome</c2>
good Job
<c2>grat</c2>
</root>

Note the <!DOCTYPE root SYSTEM "jranch.dtd">
expression.This is used to associate a DTD with an XML file.
Hope this helps.
Vasudha
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There should not be XMLDecl in dtd file such as
<?xml version="1.0" encoding="UTF-8"?>
 
maranatha trust
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there is no reason why you cant use
<?xml version="1.0" encoding="UTF-8"?>
in your dtd..it gives you no errors. I just tried it out
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are many official (standard) DTDs on the web, just find one with XML declaration inside, please. Thanks!
To my understanding, DTD is not XML, XML declaration should not be there. If some XML parser does not check DTD, I guess it is not its job, it does not make it correct. Of course, I could be wrong, but I'll wait ...
 
maranatha trust
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It may not be correct to include the <?xml ... in your dtd but its not illegal! Pls try it out
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic