2010-03-31 18 views
35

Tengo una página xhtml validando bajo doctype estricto xhtml, pero obtengo esta advertencia que intento comprender y corregir.Cómo corregir la advertencia de validación de "Marca de orden por bytes en el archivo UTF-8"

Simplemente, cómo puedo ubicar esta "Marca de Byte" errónea. Estoy editando mi archivo usando Visual Studio, no estoy seguro si eso ayuda.

Warning Byte-Order Mark found in UTF-8 File.

The Unicode Byte-Order Mark (BOM) in UTF-8 encoded files is known to cause problems for some text editors and older browsers. You may want to consider avoiding its use until it is better supported.

Respuesta

44

La parte ubicación de su pregunta es simple: El byte-order mark (BOM) será al principio del archivo.

Al editar el archivo, vaya al File | Advanced Save Options... y encontrará un menú desplegable "Codificación" (junto con un menú desplegable "Fin de línea"). Probablemente esté configurado para usar "Unicode (UTF-8 con firma) - Página de códigos 65001". Si se desplaza un poco hacia abajo, puede encontrar "Unicode (UTF-8 sin firma) - Página de códigos 65001". Eso debería hacerlo (si quieres). Algunos sistemas pueden confundirse con una lista de materiales en un archivo UTF-8, como lo indica la advertencia.

Consulte también this note en las preguntas más frecuentes del sitio Unicode sobre los archivos BOM y UTF-8. No tiene otra función más que decir que el archivo es, de hecho, UTF-8. En particular, no tiene ningún efecto en el orden de bytes (la razón principal por la que tenemos listas de materiales), porque el orden de bytes de UTF-8 es fijo.

+0

Tenía la intención de votar esto, pero lo voté accidentalmente y no me di cuenta por 2 días, y ahora está bloqueado y no me deja cambiarlo ... pero esto me ayudó a corregir las advertencias w3c que estaban molestándome, así que gracias de todos modos. – andygoestohollywood

+1

@andygoestohollywood: :-) Gracias por explicarme, me pregunté en el momento por qué alguien había votado negativamente la respuesta. Podría editar la respuesta para poder deshacerla, pero no veo nada constructivo para cambiar y no me gusta presionarlo en la lista "activa" solo para revertir una votación. Me alegro de que esto ayudó! –

17

Así es como me fijo esto:

  1. Descargar e instalar Notepad++

  2. Abrir el archivo con Notepad ++

  3. En el menú seleccione "Codificación" y otra vez en "Codificar en UTF-8 sin lista de materiales "

  4. Guarde el archivo y la lista de materiales se habrá ido.

0

En Linux:

Abrir el archivo con Geany.

En el menú "Dokument" desmarque "Escribir Unicode BOM".

Guarde el archivo.

0

BOM a veces se encuentra dentro del texto, no al principio - si un archivo ha sido ensamblado alguna vez por php desde otros archivos usando por ejemplo include_once(). Para eliminarlo, elimine el área entre al menos un carácter antes de la BOM y al menos un carácter después de la BOM (por si acaso). La posición de BOM se puede ubicar en F12 Developer Tools de Internet Explorer y probablemente Edge. Se visualiza como rombo/rombo negro.

Visual Studio y WebMatrix pueden guardar archivos con o sin firma (al principio).

BOM provoca errores durante la validación (https://validator.w3.org/#validate_by_upload) o en consolas - </HEAD> pueden ser tratados como elemento huérfanos sin < HEAD>, al parecer, está presente:

Error: Stray end tag head.

< BODY> como segunda! < BODY>, cuando sólo uno < BODY> existe y todo es correcto:

Error: Start tag body seen but an element of the same type was already open.

y todo el documento se puede ver que carece de DOCTYPE, cuando BOM BOM o dos S ocupan la primera línea y DOCTYPE está en segunda línea, con un mensaje similar a este:

Error: Non-space characters found without seeing a doctype first. Expected e.g. <!DOCTYPE html>.

Error: Element head is missing a required instance of child element title.

Error: Stray doctype.

Error: Stray start tag html.

Error: Stray start tag head.

Error: Attribute name not allowed on element meta at this point.

Error: Element meta is missing one or more of the following attributes: itemprop, property.

Error: Attribute http-equiv not allowed on element meta at this point.

Error: Element meta is missing one or more of the following attributes: itemprop, property.

Error: Attribute name not allowed on element meta at this point.

Error: Element meta is missing one or more of the following attributes: itemprop, property.

Error: Element link is missing required attribute property.

Error: Attribute name not allowed on element meta at this point.

Error: Element meta is missing one or more of the following attributes: itemprop, property.

Error: Attribute name not allowed on element meta at this point.

Error: Element meta is missing one or more of the following attributes: itemprop, property.

Error: Attribute name not allowed on element meta at this point.

Error: Element meta is missing one or more of the following attributes: itemprop, property.

Error: Element title not allowed as child of element body in this context. (Suppressing further errors from this subtree.)

Error: Element style not allowed as child of element body in this context. (Suppressing further errors from this subtree.)

Error: Stray end tag head.

Error: Start tag body seen but an element of the same type was already open.

Fatal Error: Cannot recover after last error. Any further errors will be ignored.

(https://validator.w3.org/#validate_by_uri)

Y flujo de mensajes en IE consola F12 Herramientas de Desarrollo:

HTML1527: DOCTYPE expected. Consider adding a valid HTML5 doctype: "<!DOCTYPE html>".

HTML1502: Unexpected DOCTYPE. Only one DOCTYPE is allowed and it must occur before any elements.

HTML1513: Extra "<html>" tag found. Only one "<html>" tag should exist per document.

HTML1503: Unexpected start tag. HTML1512: Unmatched end tag.

Todo causado por una lista de materiales en el principio. Y Depurador muestra un rombo negro en la primera línea.

Los archivos guardados con firma, pero no ensamblados por php, no causan tales errores y los diamantes negros no son visibles en el depurador de IE. Entonces quizás php transforme BOM de alguna manera. Parece que el archivo php principal se debe guardar con la firma para ver esto.

Esos caracteres extraños se producen al principio y/o en los bordes de los archivos combinados con include_once() y no son visibles cuando los archivos se guardan antes sin firma. Esta es la razón por la que apunta a la implicación en la lista de materiales.

He notado esto todo anteayer cuando comencé a convertir mi sitio web a HTML5 y validarlo.

BOM también puede crear una pequeña sangría al principio de la línea. Dos archivos que contienen texto idéntico pero uno con sangría.

Cuestiones relacionadas