More Related Content
PDF
PPTX
PPTX
PPTX
PDF
HTML5など社内勉強会 Vol.1 - HTML, CSS, HTML5 PDF
PDF
PDF
WordPress on Auzre Websites More from Hiraku Nakano
PPTX
PDF
composerの遅さをまじめに考える #phpstudy PDF
PDF
Scrutinizer CIでPHPも静的解析 #phpstudy PDF
PDF
PSR-3 Logger Interfaceの紹介 PDF
PPTX
PDF
Recently uploaded
PDF
エンジニアが選ぶべきAIエディタ & Antigravity 活用例@ウェビナー「触ってみてどうだった?Google Antigravity 既存IDEと... PPTX
楽々ナレッジベース「楽ナレ」3種比較 - Dify / AWS S3 Vector / Google File Search Tool PDF
流行りに乗っかるClaris FileMaker 〜AI関連機能の紹介〜 by 合同会社イボルブ PDF
20251210_MultiDevinForEnterprise on Devin 1st Anniv Meetup PDF
Machine Tests Benchmark Suite. Explain github.com/alexziskind1/machine_tests #2 PDF
Machine Tests Benchmark Suite. Explain github.com/alexziskind1/machine_tests #1 Xml builderの紹介
- 1.
- 2.
@Hiraku (中野拓)
某ポータルサイトのPHPプログラマ
PHP歴4年
好きなフレームワーク
Zend Framework
YAF
自己紹介
http://blog.tojiru.net/
https://github.com/hirak
- 3.
- 4.
RSS, Atom
WebAPI
GData
OData
KML
Gadget.xml
何とか.xmlたくさん
XMLと言えば
まだまだ現役
- 5.
- 6.
- 7.
<?php $data =range(0,3) ?>
<?xml version="1.0" encoding="UTF-8"?>
<root>
<?php foreach ($data as $v): ?>
<child><?php echo $v?></child>
<?php endforeach ?>
</root>
文字列連結
- 8.
< “ >& → < " > &
エスケープを確実に
壊れたXMLになってしまうかも
タグの対応
インデントを保つのがつらい
文字列連結の問題
→おすすめしない
- 9.
- 10.
- 11.
- 12.
<?php
$doc = newDOMDocument('1.0', 'UTF-8');
$doc->formatOutput = true;
$root = $doc->createElement('root');
$root->setAttribute('xmlns', 'http://example.com/');
$child = $doc->createElement('child');
$text = $doc->createTextNode('foo');
$child->appendChild($text);
$root->appendChild($child);
$doc->appendChild($root);
echo $doc->saveXML();
DOMのコード
- 13.
- 14.
- 15.
- 16.
- 17.
XMLWriterのコード
<?php
$w = newXMLWriter;
$w->openURI('php://output');
$w->setIndent(true);
$w->setIndentString(' ');
$w->startDocument('1.0','UTF-8');
$w->startElement('root');
$w->writeAttribute('xmlns',
'http://example.com/');
$w->startElement('child');
$w->text('foo');
$w->endElement();
$w->endELement();
$w->endDocument();
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
classでバックエンドの切り替え
dom,xmlwriter, array
formatOutput
encoding, version
$json_builder = XML_Builder::factory(array(
'class' => 'array',
'serializer' => 'json_encode',
));
factory()のオプション
- 27.
- 28.
- 29.
$hoge = 'Foo'
/*... */
->$hoge($hoge)
/* ... */
->{$hoge . '_'}($hoge)
変数
←要素名もテキストも変数が
使える
←要素名に複雑な文字列を使う
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 38.
- 39.
<?php
require_once 'XML/Builder.php';
XML_Builder::factory(array('doctype' =>XML_Builder::$HTML4_TRANSITIONAL))
->html(array('lang' => 'ja'))
->head
->meta_(array(
'http-equiv' => 'Content-Type',
'content' => 'text/html; charset=UTF-8'
))
->meta_(array(
'http-equiv' => 'Content-Style-Type',
'content' => 'text/css'
))
->meta_(array(
'http-equiv' => 'Content-Script-Type',
'content' => 'text/javascript'
))
->meta_(array('name' => 'robots', 'content' => 'INDEX,FOLLOW'))
->title_('DOMで HTML かいたりしませんか')
->_
->body_
->_
->_echo;
- 40.