PHP5のdomを使ってRSS1.0用のxmlファイルを自動生成しようと
試みているのですが、RSS1.0用にネームスペースを記述しようとしても
なかなか理想通りに行きません。
理想としては下記のように表示したいのですが
<rdf:RDF
xmlns="http://purl.org/rss/1.0/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xml:lang="ja">
現時点では『xmlns="http://purl.org/rss/1.0/"』が表示出来ません。
<?xml version="1.0" encoding="utf-8" ?>
<rdf:RDF
(ここが抜けている)
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:lang="ja">
書いたソースコードを記載します。
$doc = new DOMDocument('1.0', 'utf-8');
$doc->formatOutput = true;
$root = $doc->createElementNS('http://purl.org/rss/1.0/', 'rdf:RDF');
$doc->appendChild($root);
$root->setAttributeNS($NAMESPACE ,'xmlns:rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
$root->setAttributeNS($NAMESPACE ,'xmlns:dc', 'http://purl.org/dc/elements/1.1/');
$root->setAttributeNS($NAMESPACE ,'xmlns:lang', 'ja');
setAttributeNSで色々と試してみたのですが、『xmlns=』と言う形に出来ませんでした。
初歩的な質問で大変申し訳ありませんが
皆様のお力添えを頂ければと思います。
宜しくお願い致します。
No.5ベストアンサー
- 回答日時:
<?php //とりあえず出ればいいんかな..? v5.2.8
$doc = new DOMDocument('1.0', 'utf-8');
$root = $doc->createElement('rdf:RDF');
$doc->appendChild($root);
$doc->createAttributeNS('http://purl.org/rss/1.0/', 'xmlns');
$root->setAttribute('xmlns:rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
$root->setAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
$root->setAttribute('xml:lang', 'ja');
print '<xmp>' . $doc->saveXML($root);
No.4
- 回答日時:
ご協力有難う御座いました。
PHPのバグの可能性もあるという事なのですね…
ちょっと別のやり方も試して見ます。
本当に感謝致します。 _(._.) _
No.3
- 回答日時:
多分PHPのバグです。
名前空間URIとして空文字列を指定した場合,xmlns属性が付与できました。同じことをJavaでやると,DOMの仕様どおり NAMESPACE_ERRが投げられます。
No.1
- 回答日時:
メモ:
http://www.w3.org/TR/xml-names/#ns-decl
Namespace constraint: Reserved Prefixes and Namespace Names
The prefix xml is by definition bound to the namespace name http://www.w3.org/XML/1998/namespace. It MAY, but need not, be declared, and MUST NOT be bound to any other namespace name. Other prefixes MUST NOT be bound to this namespace name, and it MUST NOT be declared as the default namespace.
The prefix xmlns is used only to declare namespace bindings and is by definition bound to the namespace name http://www.w3.org/2000/xmlns/. It MUST NOT be declared . Other prefixes MUST NOT be bound to this namespace name, and it MUST NOT be declared as the default namespace. Element names MUST NOT have the prefix xmlns.
All other prefixes beginning with the three-letter sequence x, m, l, in any case combination, are reserved. This means that:
*users SHOULD NOT use them except as defined by later specifications
*processors MUST NOT treat them as fatal errors.
===========================
http://www.w3.org/TR/DOM-Level-2-Core/core.html# …
NAMESPACE_ERR: Raised if the qualifiedName is malformed, if the qualifiedName has a prefix and the namespaceURI is null, if the qualifiedName has a prefix that is "xml" and the namespaceURI is different from "http://www.w3.org/XML/1998/namespace", or 【if the qualifiedName is "xmlns" and the namespaceURI is different from "http://www.w3.org/2000/xmlns/"】.
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
似たような質問が見つかりました
- ASP・SaaS FC2 BLOG <AUDIO TAGを入れプレビューはOk テーンプレートを更新すると ✖ 1 2023/08/14 11:40
- HTML・CSS 疑似要素で背景画像に指定したSVG画像の色変更 2 2023/01/30 22:45
- JavaScript html5に変えるとスライドショーが消えてしまった。 3 2022/03/26 19:53
- HTML・CSS (Javascript)印刷するファイルに応じて印刷プレビュー画面で用紙を自動的に切り替えたい!! 2 2022/04/11 12:04
- JavaScript セレクトボックスを2つ設けて選択して初めてメッセを表示 1 2022/07/27 12:15
- JavaScript switch文のswitch(n)の部分を複数の値にするか、if文に変えてほしいです。 1 2022/07/27 17:18
- その他(開発・運用・管理) 【至急】.htaccessによるディレクトリ単位でのリダイレクト 2 2023/08/10 13:46
- PHP PHPでCookieを使った訪問回数について 1 2023/05/28 14:10
- アプリ Android studio 初心者 Hello Android!しか表示されない 1 2023/08/01 08:47
- PHP PHPのエラーの解消法について教えて下さい。 1 2023/02/06 10:48
関連するカテゴリからQ&Aを探す
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
VBA で、スペースを含むファイ...
-
【PHP】void関数についてよく理...
-
画像をDBに登録できない
-
$a = ( $b == $c ) ? $d、 この...
-
PHP複数検索について
-
空文字
-
PHPで入力フォームでデータを確...
-
ファイル名を変更してアップロ...
-
マクロ(VBA)について
-
PHPでのエラー(unexpected T_S...
-
ファイルのアップロードが出来ない
-
IPアドレスによる振り分け
-
POSTの項目に追加
-
PHPのリロード時の処理
-
PHP DBデータ登録
-
csvファイルチェック
-
foreachがうまく動かない
-
【かなり初歩的な質問です】php...
-
画像アップロード時の複数パタ...
-
検索結果の出力先を違うフレー...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
VBA で、スペースを含むファイ...
-
Flaskでサーバー立ち上げに関して
-
POSTの項目に追加
-
ファイル名を変更してアップロ...
-
PHPで入力フォームでデータを確...
-
foreachがうまく動かない
-
PHP MySql 画像を取得
-
phpで変数を使ってcopyできない
-
PHPからHTMLへの変数の受け...
-
サブフォルダ内の全てのテキス...
-
UPDATEできない
-
php+mysqlでの重複チェックにつ...
-
phpでショッピングカート機能を...
-
fputcsv()で1レコード1行になる...
-
openCVのトラックバーについて
-
$a = ( $b == $c ) ? $d、 この...
-
if文のなかで
-
配列の値
-
sqlite文字列を格納、出力
-
ファイルアップローダーで送信...
おすすめ情報