发布新日志

  • Fixit - Valid Markup

    2010-07-20 16:30:09

      This test runs an XML parser on your document to check if your page validates against its specified schema. A schema (or DTD) constrains the structure and content of an XML document. An XML document which is well-formed and which complies with its schema is said to be valid. Put simply, the schema specifies rules about the structure and content of a document, and your document must follow these rules (as well as general XML well-formedness rules). If the XML parser finds something wrong with your document, then an error message will be displayed. Some errors cause the parser to stop dead in its tracks, while some errors are not so serious, and the parser can continue.

    Understanding the validator error messages

    The output of the validator can sometimes be misleading. A list of the most common messages and their remedies are included below:

    The content of element type "body" must match...
    The content of element type "form" must match...
    The reference to entity "&" must end with the ';' delimiter.
    Attribute "attr" must be declared for element type "element".
    Element type "element" must be declared.
    White spaces are required between publicId and systemId.
    The system identifier must begin with either a single or double quote character.
    Content is not allowed in prolog.
    The processing instruction target matching "[xX][mM][lL]" is not allowed.
    XML document structures must start and end within the same entity.
    The element type "element" must be terminated by the matching end-tag "</element>".
    The processing instruction must begin with the name of the target.
    Open quote is expected for attribute "attr" associated with an element type "element".

     

    The content of element type "body" must match "(h1|h2|h3|h4|h5|h6|ul|ol|dl|p|div|pre|blockquote|address|hr|table|form.|fieldset)*".

    Cause: Only certain tags are allowed immediately after the <body> tag

    Solution: This message indicates that markup immediately following the <body> tag should be one of the tags in the list e.g.

    Incorrect:

     <body>
     Hello World!
     </body>
     

    Correct:

     <body>
     <p>
     Hello World!
     </p>
     </body>
     

     

    The content of element type "form" must match "(h1|h2|h3|h4|h5|h6|ul|ol|dl|p|div|pre|blockquote|address|hr|table|fieldset)+".

    Cause: Only certain tags are allowed immediately after the &lt;form&gt; tag

    Solution: This message is very similar to the previous one. Markup immediately following the &lt;form&gt; tag should be one of the tags in the list:

     

     

    The reference to entity "&" must end with the ';' delimiter.

    Cause: This message is often displayed where the '&' characters in a URL have not been converted to their corresponding XML entity.

    Solution: Escape special characters such as '&'

    Correct:

     <a href="http://example.mobi?fname=joe&amp;lname=blogs">...</a>
     

    Incorrect:

     <a href="http://example.mobi?fname=joe&lname=blogs">...</a>
     

     

     

    Attribute "attr_name" must be declared for element type "element_name".

    Cause: This type of message simply means that you may not include attribute attr_name for the element element_name.

    Solution: To fix the problem, simply omit the offending attribute: e.g. if you receive the message:

    Attribute "name" must be declared for element type "form".

    Remove the name attribute e.g.

     <form name="myform" id="myform" ...>

    becomes

     <form.  id="myform" ...>

    And if you receive the message:

     Attribute "cellpadding" must be declared for element type "table".

    Remove the cellpadding attribute e.g.

    <table cellpadding="10px" ...> becomes <table>

     

    If the attribute is a styling attribute and you want to maintain your styling, then you could move the attribute from the tag markup and into a stylesheet. For example, the line:

    <td bgcolor="#009900" height="25">Hello World!</td>

     

    would produce the following validation errors:

     Attribute "bgcolor" must be declared for element type "td".
     Attribute "height" must be declared for element type "td".

     

    To remedy this without losing your styling, you move the attributes bgcolor and height into a CSS style. So the original markup becomes:

     <td class="mystyle">Hello World!</td>
     

     

    And a new style. called mystyle is defined:

       td.mystyle {
         background-color: #009900;
         line-height: 25px; 
       }
     

     

    However, you need to be careful here. Sometimes the CSS attributes have different names to their HTML counterparts. In this case bgcolorbecomes background-color, and height becomes line-height.Please refer to the CSS specification to find out what attributes are available to use.

     

    Element type "element_name" must be declared.

    Cause: This means that the element "element_name" has not been specified in the DTD. Thus, it can't be used in your document.

    Solution: To remedy, simpy remove the <element_name> tag. This applies to any error message of the form. e.g.

    If you receive the message:

    Element type "font" must be declared.

    Then you should remove the occurence of the <font> tag from your markup.

     

     

    White spaces are required between publicId and systemId.

    Cause: There is no space between the public and system identifiers in the DOCTYPE declaration

    Solution: To fix this, simply put a space, a newline, or a tab between the public and system identifiers in the DOCTYPE declaration e.g.

    Correct:

      <!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" 
      "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">

     

    Incorrect:

    <!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" 
      "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
     

     

     

    The system identifier must begin with either a single or double quote character.

    Cause: The system identifier (a URL to a copy of the DTD) of the DOCTYPE declaration is not surrounded by quotes

    Solution: Put quotes around the system id e.g.

    Incorrect:

    <!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" http://www.wapforum.org/DTD/xhtml-mobile10.dtd>

     

    Correct:

    <!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">

     

     

    Content is not allowed in prolog.

    Cause: There is extraneous text at the beginning of the document.

    Solution: Remove any text occuring before the XML declaration. Comments are allowed, but must not occur before the XML decalaration e.g.

    Not permitted:

      <!-- This is a comment before the XML declaration - this is not allowed -->
      <?xml version="1.0" ?>   
      <!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">

     

    Not permitted:

      <?xml version="1.0" ?>
      This is some content before the DOCTYPE declaration - this is not allowed 
      <!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
     

     


    Permitted:

      <?xml version="1.0" ?>
      <!-- This is a comment before the XML declaration - this is allowed-->
      <!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
     

     

     

    The processing instruction target matching "[xX][mM][lL]" is not allowed.

    Cause: This message can occur where there is extraneous text at the very beginning of the document.

    Solution: Remove any text preceding the XML declaration. Comments are permitted before the DOCTYPE declaration, but not before the XML decalaration. See previous error message.

     

    XML document structures must start and end within the same entity.

    Cause: This message can occur when the closing <html> tag is missing

    Solution: Make sure there is a closing </html> tag at the end of your document

     

     

    The element type "" must be terminated by the matching end-tag "".

    Cause: This might occur when tags are not properly nested, or of the name of closing tag has been mispelled.

    Solution: Check that your tags are correctly nested and closed properly.

     

     

    The processing instruction must begin with the name of the target.

    Cause: A possible cause of this message is where the the XML declaration is incorrect, for example where extra spaces have been inserted

    Solution: Ensure the XML declaration and any processing instructions (lines beginning <?.... ?> have been properly stated e.g.

    Incorrect:

    <? xml version="1.0" ?>

     

    Correct:

    <?xml version="1.0" ?>

    Open quote is expected for attribute "attr" associated with an element type "element".

    Cause: This message is genereated when an attribute value is specified without enclosing it in quotes

    Solution: Make sure that all attributes are enclosed in quotes (either single or double quotes will do). For example, if the error message is:

    Open quote is expected for attribute "rel" associated with an element type "link".

    then you should locate the offending occurence of the rel attribute within the link tag, and place quotes around its value:

    Incorrect:

    <link rel=stylesheet href="style.css" type="text/css">

     

    Correct:

    <link rel="stylesheet" href="style.css" type="text/css">
    
  • xml基础-xml、DTD、xml schema

    2009-06-14 19:49:18

    xml
Open Toolbar