【发布时间】:2020-04-21 21:19:40
【问题描述】:
谁能告诉我为什么这个 XPath 表达式无效?
/ReaderDetails/Reader[Pin=('2325', '2421', '2424')]
完整代码:
$dream_team_pins = implode('\', \'', array_map('trim',explode(',',get_option('dream_team_readers'))));
// Takes a comma separated list, converts to an array, and then implodes to a quoted comma separated list.
// This is currently outputting 2325', '2421', '2424 (the missing quotes at start and end are intentional)
$expression = '/ReaderDetails/Reader[Pin=(\''.$dream_team_pins.'\')]';
// I'm adding the single quotes at the start and end back in here so the entire expression is
// outputting /ReaderDetails/Reader[Pin=('2325', '2421', '2424')]
$dream_team_readers = $readers->xpath($expression);
但我不断得到
警告:SimpleXMLElement::xpath():无效的表达式。
简而言之,我希望能够将多个值传递给一个 xpath 表达式(取自逗号分隔的字符串)来过滤 XML 数组。
对我的表达有什么建议吗?
【问题讨论】:
标签: xml xpath xpath-2.0 xpath-1.0