0

私はこのような xml ドキュメントを持っています (実際の xml は大きいため、単なる例です):

<document>
<vol>
<sens>A</sens>
<date_vol>2013-05-26 00:00:00</date_vol>
<compagnie>AZA</compagnie>
<num_vol>802</num_vol>
<destination>FCO</destination>
<horaire>1900-01-01 00:20:00</horaire>
<statut>ARRIVE 00:45</statut>
</vol>
<vol>
<sens>A</sens>
<date_vol>2013-05-27 00:00:00</date_vol>
<compagnie>AZA</compagnie>
<num_vol>802</num_vol>
<destination>FCO</destination>
<horaire>1900-01-01 00:20:00</horaire>
<statut>ARRIVE 00:13</statut>
</vol>

次のようにphpを使用してこのドキュメントをクエリしたいと思います:

$simpleXml = new SimpleXMLElement($xml);
$vols = $simpleXml->xpath("/document/vol[sens='$sens_vols' and date_vol='2013-05-26 00:00:00' and horaire>'1900-01-01 00:20:00']");

これは機能しません。空白の結果が得られますが、クエリから最後の and を削除すると (this: and horaire>'1900-01-01 00:20:00') 機能し、どこかに問題があると思います私のコードでは、「=」で機能するため、「>」記号で文字列を照会すると. 誰かが何が悪いのか教えてもらえますか? ありがとう

4

2 に答える 2

1

XPath 1.0 では、そのように比較するには、最初に関数を使用して-,:およびスペース文字を削除する必要がありtranslate()ます...

$vols = $simpleXml->xpath('/document/vol[sens="$sens_vols" and date_vol = "2013-05-26 00:00:00" and translate(translate(translate(horaire, "-", "")," ",""),":","") > translate(translate(translate("1900-01-01 00:20:00"", "-", "")," ",""),":","")]');

関数を使用する XPath 2.0 ではより簡単ですcompare()が、XPath 2.0 はまだ広く実装されていません。

于 2013-05-27T18:03:20.797 に答える