PHP DOM支持的DOM核心级别/版本是什么? [英] What is the DOM Core Level / Version Supported by PHP DOM?

查看:125
本文介绍了PHP DOM支持的DOM核心级别/版本是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PHP DOM支持哪些DOM Core版本?我可以看到有许多不同的列表(列表):





支持哪一个?

解决方案

PHP DOM扩展具有文件对象模型(核心)1级功能。您可以测试featu res,使用帮助方法实现,然后测试功能和版本,这里是四个功能的摘要:




  • 一个核心找到的版本:'1.0'

  • 找到四个 XML 版本: '2.0'; 1.0’ ; ;

  • 找到 版本

  • XHTML <

  • 找到 XPath 版本



这个结果与规范相结合 如果不是这样的话。 Core Core 功能在1.0级需要返回 TRUE 以及非指定版本(此处为'' NULL ),但结果显示,它不。所以即使DOM Core Level 1被宣布为功能,它也被破坏。



另外 XML 功能不能为2.0级,如果 Core 不支持2.0级的功能 - 这是这种情况,Core Level 2.0是不支持的功能。



DOM中的功能( 来源):





示例脚本的示例输出:

 核心功能在PHP DOMDocument实现中:

1.)Core'3.0':FALSE
2.)Core'2.0':FALSE
3.)Core'1.0':TRUE
4.)Core'':FALSE
5.)核心NULL:FALSE

发现一个核心版本:'1.0'。

XML功能在PHP DOMDocument实现中:

1.)XML'3.0':FALSE
2.)XML'2.0':TRUE
3.)XML'1.0':TRUE
4.)XML'':TRUE
5.)XML NULL:TRUE

找到四个XML版本:'2.0' 1.0’ ; ;空值。

HTML功能在PHP DOMDocument实现中:

1.)HTML'3.0':FALSE
2.)HTML'2.0':FALSE
3.)HTML'1.0':FALSE
4.)HTML':FALSE
5.)HTML NULL:FALSE

找到的HTML版本为零。

XHTML功能在PHP DOMDocument实现中:

1.)XHTML'3.0':FALSE
2.)XHTML'2.0':FALSE
3.)XHTML'1.0':FALSE
4.)XHTML'':FALSE
5.)XHTML NULL:FALSE

找到零XHTML版本。

XPath功能在PHP DOMDocument实现中:

1.)XPath'3.0':FALSE
2.)XPath'2.0':FALSE
3.)XPath'1.0':FALSE
4.)XPath'':FALSE
5.)XPath NULL:FALSE

找到的XPath版本为零。

示例脚本:

 <?php 
/ **
* PHP DOM支持哪些DOM Core版本?
* @link http://stackoverflow.com/a/17340953/367456
* /

$ dom = new DOMDocument();
$ dom-> loadXML('< root />');

$ versionsArray = ['3.0','2.0','1.0','',NULL];
$ features = [
#文档对象模型(DOM)< http://www.w3.org/DOM/DOMTR>
'Core'=> $ versionsArray,

#文档对象模型(DOM)< http://www.w3.org/DOM/DOMTR>
'XML'=> $ versionsArray,

#文档对象模型(DOM)2级HTML规范< http://www.w3.org/TR/DOM-Level-2-HTML/>
'HTML'=> $ versionsArray,
'XHTML'=> $ versionsArray,

#文档对象模型XPath< http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html>
XPath=> $ versionsArray,
];

const DISPLAY_TITLE = 1;
const DISPLAY_DETAILS = 2;
const DISPLAY_SUMMARY = 4;
const DISPLAY_ALL = 7;

dom_list_features($ dom,$ features);

函数dom_list_features(DOMDocument $ dom,array $ features,$ display = DISPLAY_ALL){

foreach($ features as $ feature => $ versions){
dom_list_feature($ dom,$ feature,$ versions,$ display);
}
}

函数dom_list_feature(DOMDocument $ dom,$ feature,array $ versions,$ display){

if($ display& DISPLAY_TITLE){
echo$ feature功能在PHP DOMDocument实现中:\\\
\\\
;
}

$ found = [];

foreach($ versions as $ i => $ version){
$ result = $ dom-> implementation-> hasFeature($ feature,$ version);
if($ result){
$ found [] = $ version;
}

if($ display& DISPLAY_DETAILS){
printf(%d。)$ feature%'-5s:%s\\\
,$ i + 1,var_export($ version,true),$ result? '真假');
}
}

if($ display& DISPLAY_DETAILS){
echo\\\
;
}

$ formatter = new NumberFormatter('en_UK',NumberFormatter :: SPELLOUT);
$ count = ucfirst($ formatter-> format(count($ found)));
$ found = array_map(function($ v){
return var_export($ v,TRUE);
},$ found);

if($ display& DISPLAY_SUMMARY){
printf(%s%s versions found%s.\\\
\\\
,$ count,$ feature,$ found? ':'。implode(';',$ found):'');
}
}


What is the DOM Core Version is Supported by PHP DOM? I can see there are many different ones listed like (list):

Which one is supported?

解决方案

PHP DOM Extension has the Document Object Model (Core) Level 1 feature. You can test for features that are implemented with a helper method and then testing for features and versions, here a summary for four features:

  • One Core versions found: '1.0'.
  • Four XML versions found: '2.0'; '1.0'; ''; NULL.
  • Zero HTML versions found.
  • Zero XHTML versions found.
  • Zero XPath versions found.

This result combine with the specs is puzzeling if not esoteric. The Core Feature in Level 1.0 requires to return TRUE as well for a non-specified version (here: for '' and NULL), but as the results show, it does not. So even DOM Core Level 1 is announced as feature, it's also broken.

Also the XML Feature can not be level 2.0 if the Core feature of level 2.0 is not supported - and this is the case here, Core Level 2.0 is not a supported feature.

Features in DOM (source):

Exemplary Output of my example script:

Core Feature is in PHP DOMDocument implementation:

    1.) Core '3.0': FALSE
    2.) Core '2.0': FALSE
    3.) Core '1.0': TRUE
    4.) Core ''   : FALSE
    5.) Core NULL : FALSE

One Core versions found: '1.0'.

XML Feature is in PHP DOMDocument implementation:

    1.) XML '3.0': FALSE
    2.) XML '2.0': TRUE
    3.) XML '1.0': TRUE
    4.) XML ''   : TRUE
    5.) XML NULL : TRUE

Four XML versions found: '2.0'; '1.0'; ''; NULL.

HTML Feature is in PHP DOMDocument implementation:

    1.) HTML '3.0': FALSE
    2.) HTML '2.0': FALSE
    3.) HTML '1.0': FALSE
    4.) HTML ''   : FALSE
    5.) HTML NULL : FALSE

Zero HTML versions found.

XHTML Feature is in PHP DOMDocument implementation:

    1.) XHTML '3.0': FALSE
    2.) XHTML '2.0': FALSE
    3.) XHTML '1.0': FALSE
    4.) XHTML ''   : FALSE
    5.) XHTML NULL : FALSE

Zero XHTML versions found.

XPath Feature is in PHP DOMDocument implementation:

    1.) XPath '3.0': FALSE
    2.) XPath '2.0': FALSE
    3.) XPath '1.0': FALSE
    4.) XPath ''   : FALSE
    5.) XPath NULL : FALSE

Zero XPath versions found.

Example script:

<?php
/**
 * What is the DOM Core Version is Supported by PHP DOM?
 * @link http://stackoverflow.com/a/17340953/367456
 */

$dom = new DOMDocument();
$dom->loadXML('<root/>');

$versionsArray = ['3.0', '2.0', '1.0', '', NULL];
$features      = [
    # Document Object Model (DOM) <http://www.w3.org/DOM/DOMTR>
    'Core'  => $versionsArray,

    # Document Object Model (DOM) <http://www.w3.org/DOM/DOMTR>
    'XML'   => $versionsArray,

    # Document Object Model (DOM) Level 2 HTML Specification <http://www.w3.org/TR/DOM-Level-2-HTML/>
    'HTML'  => $versionsArray,
    'XHTML' => $versionsArray,

    # Document Object Model XPath <http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html>
    "XPath" => $versionsArray,
];

const DISPLAY_TITLE   = 1;
const DISPLAY_DETAILS = 2;
const DISPLAY_SUMMARY = 4;
const DISPLAY_ALL     = 7;

dom_list_features($dom, $features);

function dom_list_features(DOMDocument $dom, array $features, $display = DISPLAY_ALL) {

    foreach ($features as $feature => $versions) {
        dom_list_feature($dom, $feature, $versions, $display);
    }
}

function dom_list_feature(DOMDocument $dom, $feature, array $versions, $display) {

    if ($display & DISPLAY_TITLE) {
        echo "$feature Feature is in PHP DOMDocument implementation:\n\n";
    }

    $found = [];

    foreach ($versions as $i => $version) {
        $result = $dom->implementation->hasFeature($feature, $version);
        if ($result) {
            $found[] = $version;
        }

        if ($display & DISPLAY_DETAILS) {
            printf("    %d.) $feature %' -5s: %s\n", $i + 1, var_export($version, true), $result ? 'TRUE' : 'FALSE');
        }
    }

    if ($display & DISPLAY_DETAILS) {
        echo "\n";
    }

    $formatter = new NumberFormatter('en_UK', NumberFormatter::SPELLOUT);
    $count     = ucfirst($formatter->format(count($found)));
    $found     = array_map(function ($v) {
        return var_export($v, TRUE);
    }, $found);

    if ($display & DISPLAY_SUMMARY) {
        printf("%s %s versions found%s.\n\n", $count, $feature, $found ? ': ' . implode('; ', $found) : '');
    }
}

这篇关于PHP DOM支持的DOM核心级别/版本是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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