我正在嘗試使用xpath查詢以下XML中的特定電子郵件地址。php xpath查詢xml匹配值
<?xml version="1.0"?>
<records>
<record>
<f id="6">sample data 1</f>
<f id="7">user full name 1</f>
<f id="8">first name 1</f>
<f id="9">phone number 1</f>
<f id="10">[email protected]</f>
<f id="11">user1 last name</f>
<f id="12">url 1</f>
</record>
<record>
<f id="6">sample data 2</f>
<f id="7">user full name 2</f>
<f id="8">first name 2</f>
<f id="9">phone number 2</f>
<f id="10">[email protected]</f>
<f id="11">user2 last name</f>
<f id="12">url 2</f>
</record>
<record>
<f id="6">sample data 3</f>
<f id="7">user full name 3</f>
<f id="8">first name 3</f>
<f id="9">phone number 3</f>
<f id="10">[email protected]</f>
<f id="11">user3 last name</f>
<f id="12">url 3</f>
</record>
</records>
我正在使用PHP,到目前爲止我能夠通過以下行查詢所有電子郵件地址。
$result = $xml->xpath('/records/record/f[@id="10"]');
但是,我希望能夠查詢特定的電子郵件地址,例如, 「[email protected]」。這可以用xpath在一行中完成嗎?
另外,我需要根據該電子郵件地址返回XML中的其他一些值。
例如,我想查詢XML的「[email protected]」,然後返回「用戶全名2」,「樣本數據2」等
任何幫助,將不勝感激!我對xpath比較陌生,在嘗試瀏覽W3C學校的示例之後,我將簡要介紹一下。