我需要使用XHTML文档类型在页面上声明XML吗? [英] Do I need to declare XML on a page using the XHTML doctype?

查看:82
本文介绍了我需要使用XHTML文档类型在页面上声明XML吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


$ b

 <?xml version =1.0encoding =utf-8?> 
<!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // EN
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional。 DTD>

但是,在其他地方,我看到(包括w3.org)DOCTYPE 必须成为第一个标记声明。



由于W3说明了,它必须是真实的。但是,我可能有一些关于第一种方法的页面/应用程序。我的风险是什么?



编辑:我刚刚通过 W3 Validator 有和没有XML声明,并且它通过了两种方式。此时,我猜这只是一种风格。

c><?xml version =1.0encoding =utf-8?>

...是XML的默认版本和编码,所以根本不需要它。如果您将XHTML作为text / html提供,它可能根本就不存在。


但是,在其他地方,我看到(包括w3.org)DOCTYPE必须是第一个标签。


听起来有些混乱...... DOCTYPE不是一个标签,两者都不是<?xml?>(它被称为XML声明,看起来像一个处理指令,但它不是其中之一)。



如果您同时包含这两个参数,则必须先声明XML声明。诀窍是IE6的DOCTYPE嗅探器只检测标准模式DOCTYPE,如果它们是页面上的第一件事,这意味着你不能使用XML声明,并且必须坚持使用XML 1.0和UTF-8编码(这不是很好损失)。


I've been seeing some conflicting information that an XHTML document must also declare itself as XML.

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

However, in other places I'm seeing (including w3.org) that the DOCTYPE must be the first tag declaration.

Since W3 says it, it must be true. However, I probably have some pages/apps lying about that are following the first method. What are my risks?

Edit: I just ran a page through the W3 Validator with and without the XML declaration and it passed both ways. At this point, then, I'm guessing it's just a "style" thing.

解决方案

<?xml version="1.0" encoding="utf-8"?>

...is the default version and encoding for XML, so you don't need it at all. If you are serving XHTML as text/html, it probably shouldn't be there at all.

However, in other places I'm seeing (including w3.org) that the DOCTYPE must be the first tag.

Sounds like some confusion... DOCTYPE isn't a tag and neither is <?xml?> (which is called the XML declaration, and looks like a Processing Instruction, but it isn't one of those, either).

If you are including both, the XML declaration must come first. The trick is that IE6's DOCTYPE sniffer only detects Standards Mode DOCTYPEs if they're the first thing on the page, which means you can't use an XML declaration and you must stick with XML 1.0 and UTF-8 encoding (which is no great loss).

这篇关于我需要使用XHTML文档类型在页面上声明XML吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆