xpath expression from xml with namespace prefix

前端 未结 2 564
无人共我
无人共我 2020-12-07 00:38

I could not get the following xpath expression to work when the xml path namespace prefix set.

/bk:BookStore/bk:Books/bk:Book[text()=\'Time Machine\']

2条回答
  •  南笙
    南笙 (楼主)
    2020-12-07 01:12

    Without more information about the host language (in which you attempt to evaluate XPath expressions) it is not possible to provide an useful recommendation.

    Generally, one needs to "register" a namespace with a namespace manager and this also associates a prefix to the registered namespace. Then, using this NamespaceManager object as an argument to the XPath-evaluation method, one can specify as argument to this method an XPath expression that contains names prefixed by that particular prefix.

    Workarounds:

    /*/*[name()='bk:Books']/*[name()='bk:Book' and text()='Time Machine']
    

提交回复
热议问题