下のコメントアウトしている2つのクエリをまとめたいと思っています。今のところ3行目のものを暫定で使っています。
ソースに不定期に<storong>が入ってくるので困っています。
//$entries = $xpath->query("//div[@style='FONT-SIZE: 1.4em']/ol/li/strong");
//$entries = $xpath->query("//div[@style='FONT-SIZE: 1.4em']/strong/ol/li/strong");
$entries = $xpath->query("//li/strong");
是非アドバイスお願いします。
No.1ベストアンサー
- 回答日時:
<?php
$xmlstr = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<hoge>
<div style='FONT-SIZE: 1.4em'>
<ol>
<li><strong>あああ</strong></li>
</ol>
<strong>
<ol>
<li><strong>いいい</strong></li>
</ol>
</strong>
</div>
<ul>
<li><strong>ううう</strong></li>
</ul>
</hoge>
XML;
$dom = new domDocument();
$dom->loadXML($xmlstr);
$xpath = new domXPath($dom);
$xpathstr1 = "//div[@style='FONT-SIZE: 1.4em']/ol/li/strong";
$xpathstr2 = "//div[@style='FONT-SIZE: 1.4em']/strong/ol/li/strong";
// http://www.w3.org/TR/xpath#node-sets
// The | operator computes the union of its operands, which must be node-sets.
$entries = $xpath->query($xpathstr1 . "|" . $xpathstr2 );
for ($i=0; $i < $entries->length; $i++){
$node = $entries->item($i);
print $node->textContent; //うううは表示されない
}
?>
テストしていたらお礼をするのを忘れていました。。すみません。
バッチリ動きました。
コツをつかむ必要がありそうです。Xpath。。
ありがとうございました。
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
関連するカテゴリからQ&Aを探す
おすすめ情報
- ・漫画をレンタルでお得に読める!
- ・人生のプチ美学を教えてください!!
- ・10秒目をつむったら…
- ・あなたの習慣について教えてください!!
- ・牛、豚、鶏、どれか一つ食べられなくなるとしたら?
- ・【大喜利】【投稿~9/18】 おとぎ話『桃太郎』の知られざるエピソード
- ・街中で見かけて「グッときた人」の思い出
- ・「一気に最後まで読んだ」本、教えて下さい!
- ・幼稚園時代「何組」でしたか?
- ・激凹みから立ち直る方法
- ・1つだけ過去を変えられるとしたら?
- ・【あるあるbot連動企画】あるあるbotに投稿したけど採用されなかったあるある募集
- ・【あるあるbot連動企画】フォロワー20万人のアカウントであなたのあるあるを披露してみませんか?
- ・映画のエンドロール観る派?観ない派?
- ・海外旅行から帰ってきたら、まず何を食べる?
- ・誕生日にもらった意外なもの
- ・天使と悪魔選手権
- ・ちょっと先の未来クイズ第2問
- ・【大喜利】【投稿~9/7】 ロボットの住む世界で流行ってる罰ゲームとは?
- ・推しミネラルウォーターはありますか?
- ・都道府県穴埋めゲーム
- ・この人頭いいなと思ったエピソード
- ・準・究極の選択
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
XSSで、<a><pre>タグだけを有効...
-
正規表現でタグの置換をしたい...
-
XPathで、2クエリをまとめたい
-
htmlspecialcharsで特定のタグ...
-
reuterの記事をbeautiful.soup....
-
VBAのコマンドボタンの文字列の...
-
文字の入力で横バー上段、中断...
-
ソースコードの1行が長いとき...
-
エクセルのCOUNTIFが正しくカウ...
-
メッセージボックスで1025文字...
-
最終行の改行について
-
テキストファイルから改行コー...
-
VBAでCSVをExcelに取り込む時に...
-
エスケープ文字の復帰(¥r)と...
-
preg_matchでエラーが出ます。
-
JavaMail,本文中の改行について
-
fgetws関数で読み込んだUNICODE...
-
Excel関数「COUNTIF」で”文字”...
-
海外購入PCでLENB関数を機能さ...
-
【VBA】エクセルで最後の不要な...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
変数にHTMLを代入する場合
-
PHPに書く記述を教えてください
-
PHPの正規表現でHTMLタグの内容...
-
javascriptの正規表現でhtmlか...
-
ASP.NET(C#)とhtmlの#include
-
タグの中だけ改行を除去したい
-
正規表現で複数行に渡る範囲を...
-
htmlでflashを開く、画面サイズ...
-
横1行に2種類の画像を交互に5...
-
Strutsでリンクを動的に生成したい
-
正規表現で一発置換できるでし...
-
reuterの記事をbeautiful.soup....
-
phpの正規表現でstyle="●●"を削...
-
xmlとhtmlの違いについて
-
HTMLを組み込む場合。
-
alt属性を残してタグを排除
-
正規表現でタグの置換をしたい...
-
JSFタグのfタグとは
-
URLの結合
-
htmlのソースからテーブルの値...
おすすめ情報