HTML Validation - html

My website is almost ready but I notice that my website shows in Firefox and IE look different and in chrome is fine. I have used HTML Validation to check and have 2 errors and 2 warnings. This is the details :
Line 2, Column 13: there is no attribute "XMLNS"
<html xmlns="http://www.w3.org/1999/xhtml">
✉
You have used the attribute named above in your document, but the document type you are using does not support that attribute for this element. This error is often caused by incorrect use of the "Strict" document type with a document that uses frames (e.g. you must use the "Transitional" document type to get the "target" attribute), or by using vendor proprietary extensions such as "marginheight" (this is usually fixed by using CSS to achieve the desired effect instead).
This error may also result if the element itself is not supported in the document type you are using, as an undefined element will have no supported attributes; in this case, see the element-undefined error message for further information.
How to fix: check the spelling and case of the element and attribute, (Remember XHTML is all lower-case) and/or check that they are both allowed in the chosen document type, and/or use CSS instead of this attribute. If you received this error when using the element to incorporate flash media in a Web page, see the FAQ item on valid flash.
Line 4, Column 76: NET-enabling start-tag requires SHORTTAG YES
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
✉
For the current document, the validator interprets strings like according to legacy rules that break the expectations of most authors and thus cause confusing warnings and error messages from the validator. This interpretation is triggered by HTML 4 documents or other SGML-based HTML documents. To avoid the messages, simply remove the "/" character in such contexts. NB: If you expect to be interpreted as an XML-compatible "self-closing" tag, then you need to use XHTML or HTML5.
This warning and related errors may also be caused by an unquoted attribute value containing one or more "/". Example: http://w3c.org>W3C. In such cases, the solution is to put quotation marks around the value.
Line 4, Column 77: character data is not allowed here
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
✉
You have used character data somewhere it is not permitted to appear. Mistakes that can cause this error include:
putting text directly in the body of the document without wrapping it in a container element (such as a aragraph), or forgetting to quote an attribute value (where characters such as "%" and "/" are common, but cannot appear without surrounding quotes), or using XHTML-style self-closing tags (such as ) in HTML 4.01 or earlier. To fix, remove the extra slash ('/') character. For more information about the reasons for this, see Empty elements in SGML, HTML, XML, and XHTML.
Line 44, Column 12: NET-enabling start-tag requires SHORTTAG YES
<br/>
✉
For the current document, the validator interprets strings like according to legacy rules that break the expectations of most authors and thus cause confusing warnings and error messages from the validator. This interpretation is triggered by HTML 4 documents or other SGML-based HTML documents. To avoid the messages, simply remove the "/" character in such contexts. NB: If you expect to be interpreted as an XML-compatible "self-closing" tag, then you need to use XHTML or HTML5.
This warning and related errors may also be caused by an unquoted attribute value containing one or more "/". Example: http://w3c.org>W3C. In such cases, the solution is to put quotation marks around the value.
As for Line 2, Column 13, I have added in this under header.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
However, this error is still there and I really do not know how to tidy it. On top of that, I am not a programmer and very poor in HTML....
Thank you.

You are trying to validate a document with some XHTML features as HTML 4. You are not showing the first line of the HTML document, and this would be all-important. In general, you should show a complete HTML document that reproduces the issue. But in this case, the apparent reason is wrong DOCTYPE. You should replace the existing HTML 4 DOCTYPE by one that declares some version of XHTML 1.0, if XHTML 1.0 is what you are trying to use.

Related

ATTLIST declaration in html5

Im having an issue with custom attrubutes in html5 document.
My source code starts with the following code:
<!DOCTYPE html
[
<!ATTLIST img pid ID #IMPLIED>
]>
When im trying to validate my html file in W3C validator it doesnt determine my documents doctype and tells that my doctype declaration is wrong.
So my question is, how can I declare custom attributes in HTML5? Is it even possible at the moment in HTML5? I couldnt find any relevant information on the internet.
The DOCTYPE you are trying is invalid, it should be <!DOCTYPE html> which is a valid doctype for HTML5 and as far as the custom attributes go, you need to use data- prefix which will be considered as valid custom attribute.
<p data-custom-attribute="Value"></p>
[1] A custom data attribute is an attribute in no namespace whose name
starts with the string data-, has at least one character after the
hyphen, is XML-compatible, and contains no uppercase ASCII letters.
1. Reference

Difference in display between HTML and XHTML

I thought XHTML documents were supposed to be displayed with exactly the same standards compliance mode as "strict" HTML documents.
However, there is a difference in how they display pre elements: in HTML documents, if the <pre> start tag is followed by a LF (or CRLF), this is ignored. Not so in XHTML.
Example: a HTML file and a XHTML file that have the same content, but are rendered differently.
(Or if you think it's cheating to give a HTML file and a XHTML file exactly the same content, including DOCTYPE, here are two files that follow more classic rules: HTML 4.01 strict and XHTML 1.0 strict.)
So, does that mean that statements like this W3C page's
all line breaks and spaces are rendered exactly as they appear in the HTML. The exception is a newline immediately after the start tag <pre> and immediately before the end tag </pre>, which are discarded.
are only valid for HTML, not for XHTML? I haven't found any indication that XHTML can display things differently if it likes. But all the browsers I've tested do.
The removal of the starting newline is nothing to do with the rendering in HTML, and Dave Raggett's page is just a little imprecise and getting a little out of date. The removal of the starting newline is a property of the HTML parser.
In the in body tree construction phase the HTML5 spec for the text/html mime type says:
A start tag whose tag name is one of: "pre", "listing"
If the stack of open elements has a p element in button scope, then close a p element.
Insert an HTML element for the token.
If the next token is a "LF" (U+000A) character token, then ignore that token and
move on to the next one. (Newlines at the start of pre
blocks are ignored as an authoring convenience.)
Set the frameset-ok flag to "not ok".
An XML parser is simply not allowed to do this by the XML parsing rules, so XHTML does not drop that new line.

One W3C validation errors I really want to correct

This would be my first website and I do not want to leave it these errors. Can someone please help me with these ones?
Error 1:
if (xmlhttp.readyState==4 && xmlhttp.status==200)
error: character "&" is the first character of a delimiter but occurred as data.
WHEN i &, then my AJAX code stops working
I have no clue how to correct this one.
Error 2:
…ems"><a href="brushdescription.php?id=<?php echo $popularbrushesrow['bd_brushi…
error: character "<" is the first character of a delimiter but occurred as data
Again the same error but for < this time
UPDATE:
I am using this doctype:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
< and & are some of the predefined entities in XML, which need escaping when validating the page as XML or XHTML.
< should be replaced with < (less than)
& should be replaced with & (ampersand)
However, if using these characters in JavaScript you can (instead) enclose the script in a <![CDATA[]]> section, which instructs the parser to not interpret the code as markup and will also not result in a validation error.
Try wrapping your Javascript with <![CDATA[]]> tags like so:
<script>
//<![CDATA[
// Javascript goes here.
//]]>
</script>
Also, you should look into separation of concerns. Try to move your logic out of you view. If your Javascript is in your HTML page, try to include it from a separate file.
From Wikipedia:
HyperText Markup Language (HTML), Cascading Style Sheets (CSS), and JavaScript (JS) are complementary languages used in the development of webpages and websites. HTML is mainly used for organization of webpage content, CSS is used for definition of content presentation style, and JS defines how the content interacts and behaves with the user. Historically, this was not the case though. Prior to the introduction of CSS, HTML performed both duties of defining semantics and style.
Use HTML, not XHTML (or, if you insist on using XHTML, see the guidelines on how to write XHTML that can be parsed as HTML).
I can't see how you could have generated that error. Some more context would be useful.
For the first error, consider switching from XHTML to HTML5. There's really little reason to use XHTML. Use this:
<!DOCTYPE html>
The W3C validator is for client-side code, but it seems you are trying to validate server-side code, hence the PHP tag. Send the rendered code for validation and the second error will go away. The rendered code is the one visible in the browser under "View source". You can supply the URL if it's already online somewhere.
By XML rules, “The ampersand character (&) and the left angle bracket (<) MUST NOT appear in their literal form, except when used as markup delimiters, or within a comment, a processing instruction, or a CDATA section. If they are needed elsewhere, they MUST be escaped using either numeric character references or the strings " & " and " < " respectively.” So “&&” is to be written as &&.
However, this is such works only when the document is processed as “real XHTML” due to having been sent with an XML content type, e.g. with the HTTP header Content-Type: application/xhtml+xml. Doing so implies that old versions of IE will choke on it and modern browsers will refuse to render the document at all if it contains any well-formedness error. People don’t normally do that – they just use XHTML because someone told them to do so, and their documents are sent with an HTML document type, which means among other things that script element content is processed differently. This explains why a fix that satisfies the validator makes the page break.
In the XHTML 1.0 specification, the (in)famous appendix C says: “Use external scripts if your script uses < or & or ]]> or --.” This is the simple cure if you need to use XHTML. Just put your script in an external file and “call” it with <script src="foo.js"></script>.

Get rid of “Bad value X-XRDS-Location for attribute http-equiv on XHTML element meta.” in XHTML5 validation

I have an XHTML 5 page served with application/xhtml+xml which I want to get to validate, but the validator gives me trouble in its validation results:
Line 17, Column 89: Bad value X-XRDS-Location for attribute http-equiv on XHTML element
The line in question is:
<meta http-equiv="X-XRDS-Location" content="http://shlomif.livejournal.com/data/yadis" />
How can I fix this problem? Was an arbitrary "http-equiv" value removed from the XHTML 5 specification?
http://www.w3.org/TR/html-markup/meta.html says:
Changes in HTML5
Although previous versions of HTML allowed the http-equiv attribute on the meta element to have any number of possible values, the http-equiv attribute is now restricted to only the specific values described in this reference. Also, the new charset attribute is now allowed.
So, yes, it is not allowed anymore.
In (X)HTML5, you may only use http-equiv values that are
defined in the HTML5 spec, or
registered in the WHATWG wiki page "PragmaExtensions".
If you think X-XRDS-Location would be a useful value, you’d have to register it.

Non-deprecated equivalent of <form target="...">

I want to achieve the same as...
window.open('lalala.php', 'lalala', '...');
But I want to send a HTTP POST request instead of a HTTP GET request. Thus, I'm using the following:
$('<form/>').attr('action', 'lalala.php')
.attr('target', 'lalala') // w3schools.org says this is deprecated
.attr('method', 'post')
.append(hiddenParam('param1', param1))
.append(hiddenParam('param2', param2))
.submit().remove();
// hiddenParam is a function I created that returns an input tag
// the type attribute set to hidden,
// the id attribute set to the first parameter,
// and the value attribute set to the second parameter
However, the target attribute is deprecated. Is there any way to achieve what I'm trying to do by non-deprecated means?
Use target — it isn't deprecated.
target is only missing in strict doctypes. It is not deprecated. The simplest solution is to use a transitional doctype.
All browsers that I am aware of do the right thing, even if you use a strict doctype.
If you must use a strict doctype, and you care that much about validation, then you can extend the doctype definition:
Just be aware of this 'bug' in just about every browser. The solution is to serve your XHTML as application/xhtml+xml, but this will cause IE to blow up, so you need to sniff for that browser before determining the content type. It's essentially one giant hack for a tiny check box on a validation form. It's usually a lot simpler to just use a transitional doctype.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" [ <!ATTLIST form target CDATA #IMPLIED> ]>
Add
<form target="lalala" ...></form>