开发者

XML Doctype Definition

This is my first attempt at XML. I read a lot about it before writing this, but I'm a little bit confused on if I am doing the DOCTYPE definitions correctly? Can someone take a look and let me know?

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE quiz [
<!ELEMENT quiz (items)>
<!ELEMENT items (item)>
<!ELEMENT item (question,answer)>
<!ELEMENT question (#PCDATA)>
<!ELEMENT answer (#PCDATA)>
]>
<quiz>
  <items>
    <item>
      <question>What is the name of the movie with jedis?</question>
      <answer value="0">Star Trek</answer>
      <answer value="0">E.T.</answer>
      <answer value="1">Star Wars</answer>
      <answer value="0">Titanic</answer>
    </item>
    <item>
      <question>What is my favorite color?</question>
      <answer value="0">Blue</answer>
      <answer value="1">Purple</answer>
      <answer value="0">Green</answer>
      <answer value="0">Pink</answer>
    </item>
    <item>
      <question>What comes after 2?</question>
      <answer value="1">3</answer>
      <answer value="0">1</answer>
      <answer value="0">4</answer>
      <answer value="0">11<开发者_StackOverflow社区/answer>
    </item>
  </items>
</quiz>

Also, this is obviously a quiz app. Is there a standard way of making the XML inaccessible so that people can't read the answers from pulling it up in a browser? It will be used with AJAX and PHP.


I'm not sure what your answer has to do with your DOCTYPE declaration question, but you do need corrections. You need to add some occurrence indicators and an ATTLIST declaration:

<!DOCTYPE quiz [
<!ELEMENT quiz (items)>
<!ELEMENT items (item+)>
<!ELEMENT item (question,answer+)>
<!ELEMENT question (#PCDATA)>
<!ELEMENT answer (#PCDATA)>
<!ATTLIST answer 
          value CDATA #REQUIRED> 
]>


I found the solution to this problem.

Paste the second line under the xml opening tag.

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <?xml-stylesheet href="no.xsl" type="text/xsl"?>

Make a second file named no.xsl and paste something like this:


<?xml version="1.0" encoding="iso-8859-1"?>

<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output
    doctype-public="-//W3C//DTD HTML 4.01//EN"
    doctype-system="http://www.w3.org/TR/html4/strict.dtd"
    encoding="iso-8859-1"
    indent="yes"
    method="html"
    version="4.01"/>

  <xsl:template match="/">
    <html lang="en">
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
        <meta http-equiv="REFRESH" content="0;url=http://WHEREVER YOU WANT TO REDIRECT TO">
      </head>
      <body>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

Of course, you don't have to redirect. That just works best in my case.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜