CakeFest 2024: The Official CakePHP Conference

定義済み定数

以下の定数が定義されています。 この関数の拡張モジュールが PHP 組み込みでコンパイルされているか、 実行時に動的にロードされている場合のみ使用可能です。

LIBXML_BIGLINES (int)
行数が 65535 を超えても正しく報告する

注意:

PHP 7.0.0 以降で Libxml >= 2.9.0 の場合のみ有効

LIBXML_COMPACT (int)
小さなノードを割り当てるように最適化する。アプリケーションの コードを変更することなしにスピードアップさせることができる

注意:

Libxml >= 2.6.21 でのみ有効

LIBXML_DTDATTR (int)
デフォルトのDTD属性
LIBXML_DTDLOAD (int)
外部サブセットをロードする
LIBXML_DTDVALID (int)
DTDで検証する
警告

DTD の検証を有効にすると、XML外部エンティティ参照攻撃(XXE) を容易にしてしまうかもしれません。

LIBXML_HTML_NOIMPLIED (int)
HTML_PARSE_NOIMPLIED フラグを設定する。 これは、暗黙の html/body... 要素の自動追加を無効にする。

注意:

Libxml >= 2.7.7 (PHP >= 5.4.0) でのみ有効

LIBXML_HTML_NODEFDTD (int)
HTML_PARSE_NODEFDTD フラグを設定する。 これは、doctype が見つからないときにデフォルトの doctype を追加しないようにする。

注意:

Libxml >= 2.7.8 (PHP >= 5.4.0) でのみ有効

LIBXML_NOBLANKS (int)
空白のノードを削除
LIBXML_NOCDATA (int)
CDATA をテキストノードとしてマージ
LIBXML_NOEMPTYTAG (int)
空タグを拡張する(例 <br/><br></br> にする)

注意:

このオプションは、現在 DOMDocument::save および DOMDocument::saveXML 関数でのみ有効です。

LIBXML_NOENT (int)
エンティティを置換
警告

エンティティの置換を有効にすると、XML外部エンティティ参照攻撃(XXE) を容易にしてしまうかもしれません。

LIBXML_NOERROR (int)
エラー出力を抑制
LIBXML_NONET (int)
ドキュメントロード時にネットワークアクセスを無効にする
LIBXML_NOWARNING (int)
警告出力を抑制する
LIBXML_NOXMLDECL (int)
ドキュメントの保存時に XML 宣言を削除する

注意:

Libxml >= 2.6.21 でのみ有効

LIBXML_NSCLEAN (int)
冗長な名前空間宣言を削除する
LIBXML_PARSEHUGE (int)
パーサでハードコーディングされたすべての制限を緩和するための XML_PARSE_HUGE フラグを設定する。 これは、ドキュメントやエンティティの再帰の最大数や テキストノードのサイズなどの制限に影響する。

注意:

Libxml >= 2.7.0 (PHP >= 5.3.2 あるいは PHP >= 5.2.12) でのみ有効

LIBXML_PEDANTIC (int)
XML_PARSE_PEDANTIC フラグを設定する。これは、より細かいエラー報告を出す。

注意:

PHP >= 5.4.0 でのみ有効

LIBXML_XINCLUDE (int)
XInclude 置換を実装する
LIBXML_ERR_ERROR (int)
復帰可能なエラー
LIBXML_ERR_FATAL (int)
致命的なエラー
LIBXML_ERR_NONE (int)
エラーなし
LIBXML_ERR_WARNING (int)
単純な警告
LIBXML_VERSION (int)
20605 や 20617 のような libxml のバージョン
LIBXML_DOTTED_VERSION (string)
2.6.5または2.6.17のようなlibxmlのバージョン
LIBXML_SCHEMA_CREATE (int)
XSD スキーマの検証時にデフォルト/固定の値ノードを作る

注意:

Libxml >= 2.6.14 (PHP >= 5.5.2) 以降で利用可能

add a note

User Contributed Notes 5 notes

up
8
@oneseventeen
13 years ago
When inserting XML DOM Elements inside existing XML DOM Elements that I loaded from an XML file using the following code, none of my new elements were formatted correctly, they just showed up on one line:

<?php
$dom
= DOMDocument::load('file.xml');
$dom->formatOutput = true;
//$dom->add some new elements with child nodes somewhere inside the loaded XML using insertBefore();
$dom->saveXML();
//output: everything looks normal but the new nodes are all on one line.
?>

I found I could pass LIBXML_NOBLANKS to the load method and it would reformat the whole document, including my added stuff:
<?php
$dom
= DOMDocument::load('file.xml', LIBXML_NOBLANKS);
$dom->formatOutput = true;
//$dom->add some new elements with child nodes somewhere inside the loaded XML using insertBefore();
$dom->saveXML();
//output: everything looks newly formatted, including new nodes
?>

Hope this helps, took me hours of trial and error to figure this out!
up
3
siraic at gmail dot com
3 years ago
The name of the constant LIBXML_NOENT is very misleading. Adding this flag actually causes the parser to load and insert the external entities. Omitting it leaves the tags untouched, which is probably what you want.
up
2
vetalstar at mail dot ru
6 years ago
LIBXML_DOTTED_VERSION option doesn't work.
libxml version: 2.9.4

<?php

echo LIBXML_DOTTED_VERSION;
$xml = new SimpleXMLElement('<fasa_request id="1234567"/>', LIBXML_NOXMLDECL);

?>
up
0
Ismael Miguel
8 months ago
If you want to save without the XML declaration, and LIBXML_NOXMLDECL doesn't work for you, you can just do this:

<?php
$doc
= new \DOMDocument('1.0', 'UTF-8');
$doc->loadXML($xml, LIBXML_*);

echo
$doc->saveXML($doc->firstElementChild);
?>

This will output the XML without the XML declaration and without using the flag.
You also don't need to do fiddly replacements and pray that it works.
up
0
zachatwork at gmail dot com
14 years ago
Note: The LIBXML_NOXMLDECL constant is defined in this library but is not supported by DOMDocument (yet).

See also: http://bugs.php.net/bug.php?id=47137

<?php

print "PHP_VERSION: ".PHP_VERSION."\n";
print
"LIBXML_VERSION: ".LIBXML_VERSION."\n";
print
"LIBXML_NOXMLDECL: ".LIBXML_NOXMLDECL."\n";

$dom = new DomDocument();
$dom->loadXML("<foo />");

# This should work but doesn't.

print "DOMDocument doesn't honor LIBXML_NOXMLDECL:\n";
print
$dom->saveXML(null,LIBXML_NOXMLDECL);

# This works, and will still work after the above is fixed.

print "Forwards compatible workaround:\n";
$lines = explode("\n", $dom->saveXML(null, LIBXML_NOXMLDECL), 2);
if(!
preg_match('/^\<\?xml/', $lines[0]))
print
$lines[0];
print
$lines[1];

?>

PHP_VERSION: 5.3.1-0.dotdeb.1
LIBXML_VERSION: 20632
LIBXML_NOXMLDECL: 2
DOMDocument doesn't honor LIBXML_NOXMLDECL:
<?xml version="1.0"?>
<foo/>
Forwards compatible workaround:
<foo/>
To Top