simplexml_load_file()を使って
<?xml version="1.0" encoding="UTF-8" ?>
- <Response>
- <header:Header xmlns:header="http://test.com/">
</header:Header>
- <Body>
- <itemSearch:ItemSearch xmlns:itemSearch="http://test.com/">
<count>2000</count>
<page>1</page>
......
この<count>2000</count>
の「2000」を取り出すにはどうしたらよういのでしょうか?
echo $Xml->Response->Body->itemSearch->count;
このXML文書の構成様式が初めてで(ヘッダーが付いている)、いくらやっても
取得できないので宜しくお願い致します。
No.1ベストアンサー
- 回答日時:
================Q3494329-1.xml=============
<?xml version="1.0" encoding="UTF-8" ?>
<Response>
<header:Header xmlns:header="http://test.com/">
</header:Header>
<Body>
<itemSearch:ItemSearch xmlns:itemSearch="http://test.com/">
<count>2000</count>
<page>1</page>
</itemSearch:ItemSearch>
</Body>
</Response>
=================
#!C:/Environment/PHP/v5.2.4/php-cgi.exe
<?php
//メモ
//以下、言っていること全て同じ。childrenメソッドを使う
//http://search.net-newbie.com/php/function.simple …
//http://search.net-newbie.com/php/ref.libxml.html …
//http://www.doyouphp.jp/php5/php5_simplexml.shtml
//名前空間の処理
//http://www.ibm.com/developerworks/jp/xml/library …
//等を参考にした。
header("Content-Type:text/plain;charset=UTF-8");
//LIBXML_NOWARNINGを指定しないと色々言われてしまった。
$root = simplexml_load_file('./Q3494329-1.xml','SimpleXMLElement',LIBXML_NOWARNING);
//名前空間接頭辞を使ってみましたが,以下でもOKです。count要素は「名前空間なし」なのでいったん戻す必要がある
//print $root->Body->children('http://test.com/',false)->ItemSearch-> children("")->count;
print $root->Body->children('itemSearch',true)->ItemSearch->children("")->count;
//>ヘッダーが付いている。
//多分Header要素のことでなく
//header:の部分だと思うんだけど,「ヘッダー」といわず
//「名前空間接頭辞」ときちんと言おう。せめて「header」と書いてほしかった
?>
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
関連するカテゴリからQ&Aを探す
おすすめ情報
- ・漫画をレンタルでお得に読める!
- ・人生のプチ美学を教えてください!!
- ・10秒目をつむったら…
- ・あなたの習慣について教えてください!!
- ・牛、豚、鶏、どれか一つ食べられなくなるとしたら?
- ・【大喜利】【投稿~9/18】 おとぎ話『桃太郎』の知られざるエピソード
- ・街中で見かけて「グッときた人」の思い出
- ・「一気に最後まで読んだ」本、教えて下さい!
- ・幼稚園時代「何組」でしたか?
- ・激凹みから立ち直る方法
- ・1つだけ過去を変えられるとしたら?
- ・【あるあるbot連動企画】あるあるbotに投稿したけど採用されなかったあるある募集
- ・【あるあるbot連動企画】フォロワー20万人のアカウントであなたのあるあるを披露してみませんか?
- ・映画のエンドロール観る派?観ない派?
- ・海外旅行から帰ってきたら、まず何を食べる?
- ・誕生日にもらった意外なもの
- ・天使と悪魔選手権
- ・ちょっと先の未来クイズ第2問
- ・【大喜利】【投稿~9/7】 ロボットの住む世界で流行ってる罰ゲームとは?
- ・推しミネラルウォーターはありますか?
- ・都道府県穴埋めゲーム
- ・この人頭いいなと思ったエピソード
- ・準・究極の選択
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
訪問回数が素数の場合、違うメ...
-
PHPで新しいウインドウで開く命...
-
データ送信をボタンを押さずに...
-
onedrive にexcelファイルをア...
-
GDへ値を渡す方法は?
-
PHPのif文でその処理を途中で抜...
-
フォームで戻った際に入力済み...
-
PHPでネットワークドライブのop...
-
BASP21メール送信(SMTP-AUTH認...
-
URLが.PHPってどういう...
-
Web画像コピー不可にする方法
-
これは例外処理でしょうか?
-
php文字列中のシングルクオート...
-
ネットワーク初心者です。
-
10MB以内のJPG画像
-
パースエラーとは?
-
ubuntuで、phpのパスを通す
-
fopenでファイルが開かない場合...
-
違法アップロードについて
-
VB6.0とBASP21を用いてyahooメ...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
PHPのタイムアウトについて
-
php で C言語のdefineマクロの...
-
「include」と「file_get_conte...
-
cakephpのサブタイトルはどこで...
-
phpでハイパーリンクして値を持...
-
同じような処理を一つにまとめたい
-
PHPでxmlファイルへのデータの...
-
htsp ?? <?= ?>??
-
BASIC認証のユーザー名をPHPで...
-
PHP+MySQLでXMLを作成し、それ...
-
phpのswitch文のcaseで
-
php4からphp5へ移行した際のurl...
-
PHPで、GET または POST で得ら...
-
phpのXSS対策 どこに問題が?
-
phpでcssを使う荒業
-
foreachの使い方
-
DOMでXML操作
-
PEARのHTTP_Requestをインストール
-
echoを使用すると、エラー
-
検索結果を2列で表示させたい
おすすめ情報