Skip to content

XHTML (.xhtml)

.xhtml file signature | application/xhtml+xml

Safe

Magic Bytes

Offset 0
3C 68 74 6D 6C 20 78 6D 6C 6E 73 3D

Sources: Apache Tika

Extension

.xhtml

MIME Type

application/xhtml+xml

Byte Offset

0

Risk Level

Safe

Validation Code

How to validate .xhtml files in Python

Python
def is_xhtml(file_path: str) -> bool:
    """Check if file is a valid XHTML by magic bytes."""
    signature = bytes([0x3C, 0x68, 0x74, 0x6D, 0x6C, 0x20, 0x78, 0x6D, 0x6C, 0x6E, 0x73, 0x3D])
    with open(file_path, "rb") as f:
        return f.read(12) == signature

How to validate .xhtml files in Node.js

Node.js
function isXHTML(buffer: Buffer): boolean {
  const signature = Buffer.from([0x3C, 0x68, 0x74, 0x6D, 0x6C, 0x20, 0x78, 0x6D, 0x6C, 0x6E, 0x73, 0x3D]);
  return buffer.subarray(0, 12).equals(signature);
}

How to validate .xhtml files in Go

Go
func IsXHTML(data []byte) bool {
    signature := []byte{0x3C, 0x68, 0x74, 0x6D, 0x6C, 0x20, 0x78, 0x6D, 0x6C, 0x6E, 0x73, 0x3D}
    if len(data) < 12 {
        return false
    }
    return bytes.Equal(data[:12], signature)
}

API Endpoint

GET /api/v1/xhtml
curl https://filesignature.org/api/v1/xhtml

See the full API documentation for all endpoints and parameters.

Frequently Asked Questions

What is a .xhtml file?

A .xhtml file is a XHTML file.

What are the magic bytes for .xhtml files?

The magic bytes for XHTML files are 3C 68 74 6D 6C 20 78 6D 6C 6E 73 3D at byte offset 0. These bytes uniquely identify the file format regardless of the file extension.

How do I validate a .xhtml file?

To validate a .xhtml file, read the first bytes of the file and compare them against the known magic bytes (3C 68 74 6D 6C 20 78 6D 6C 6E 73 3D) at offset 0. This is more reliable than checking the file extension alone, as extensions can be renamed.

What is the MIME type for .xhtml files?

The primary MIME type for .xhtml files is application/xhtml+xml.

Is it safe to open .xhtml files?

XHTML (.xhtml) files are generally safe to open. They are classified as low risk because they primarily contain data rather than executable code. However, always ensure files come from a trusted source.