Domanda

I have an XML file, CSS File and a DTD file. I expect that when my reference to the dtd file is invalid i.e add zzz to the name as shown below in the xml file that an error would be raised when i try to open in google Chrome. I don not get an error?. The same applies if I edit the dtd file and add the text zzz to the word Body (As shown) - it should give me an error when opening the xml file. Am i missing something ? All files are in the same directory. The css file works perfect.

XML File

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<?xml-stylesheet type="text/css" href="Style.css"?>
<!DOCTYPE Main SYSTEM "Definitionzzz.dtd">
<Main xmlns:html="http://www.w3.org/1999/xhtml">
<Heading>
Important text  
</Heading>
<Newline></Newline>
<Body>
Important text
</Body>
<Newline></Newline>
<Heading>
Important text  
</Heading>
<Newline></Newline>
<Body>
Important text  
</Body>
<Newline></Newline>
</Main>

DTD File

<!--DTD syntax-->
<!DOCTYPE Main
[
<!ELEMENT Main (Heading,Body,Newline,Bullet)>
<!ELEMENT Heading (#PCDATA)>
<!ELEMENT Bodyzzz (#PCDATA)>
<!ELEMENT Newline (#PCDATA)>
<!ELEMENT Bullet (#PCDATA)>
]>

CSS File

/* CSS For headings */
Main
{
    border-radius: 5px; 
    padding: 0;
    margin: 0;
    position: absolute; 
    top: 15px;
    left: 15px;
    right: 15px;
    bottom: 15px;
    overflow: auto;
}
Heading
{
    color: #000000;
    font-size: 20pt;
    text-align: center;
    margin-left:15px;
    text-decoration:underline;
}
/* CSS For Body */
Body
{
    color: #000000;
    font-size: 10pt;

}
/* CSS For Bullets */
Bullet
{
    color: #000000;
    font-size: 15pt;
    list-style-type: bullet;
    left: 30px;
    margin-left:30px;
}
/* CSS For Making a new line */
Newline
{
    display:block
}
/* CSS For Weblinks */
a:link:after, a:visited:after
{
content:attr(href); /*displays the actual URL*/
font-size:20pt;
display:block; /*show URLs on a separate line*/
}
È stato utile?

Soluzione

Web browsers do not do markup validation, beyond checking that XML is well-formed (that is, it is XML at all). They do not even read DTDs.

To validate an XML document, you need an XML validator. One clumsy possibility is the W3C Markup Validator. Even though it is in many ways HTML oriented, it has an SGML and XML validator as the basis, and you can use it on XML documents. You would need to put the DTD on a web server so that it can be referred to by URL, or include it in the XML document. Note that an external DTD file should not have a <!DOCTYPE Main [...]> wrapper around the declarations, as it only belongs to a case where the DTD is embedded in the XML document, e.g.

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<?xml-stylesheet type="text/css" href="Style.css"?>
<!DOCTYPE Main
[
<!ELEMENT Main (Heading,Body,Newline,Bullet)>
<!ELEMENT Heading (#PCDATA)>
<!ELEMENT Bodyzzz (#PCDATA)>
<!ELEMENT Newline (#PCDATA)>
<!ELEMENT Bullet (#PCDATA)>
]>
<Main xmlns:html="http://www.w3.org/1999/xhtml">
...

By the way, even without the zzz, the document is invalid – your DTD declares a structure that has four specific elements as children of the root element, in the specified order, and without any repetition.

Altri suggerimenti

Follow this tutorial...https://gist.github.com/Squiva/7c1a0f98c3fe820f640d You can also do this... Where node is the name of your main node, and Foobar.dtd is the path to your DTD file. Enjoy your Document Type Definitions.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top