我正在尝试使用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学校的示例之后,我将简要介绍一下。