2014-10-06 2 views
8

"Ethical"에서 시작하여 내부 텍스트를 가져오고 "and"를 포함하고 Heading 노드에서 "consent"로 끝내고 싶습니다.XPath에서 starts-with(), contains() 및 ends-with()를 사용하여 xml 노드 innertext를 찾는 방법? in XPATH 1.0

+1

어떤 버전의 XPath (또는 확실하게 버전을 모르는 경우 어떤 도구/라이브러리/언어)? 'starts-with'는 XPath 1.0에서 사용할 수 있지만'ends-with'는 XPath 2.0에서만 도입되었습니다 (1.0에서는'substring'과'string-length'로 위조해야합니다). –

+1

XPath 1.0 만 사용합니다 –

+0

질문에 명확하지 않습니다. 예를 들어 예상되는 결과는 무엇입니까? –

답변

19

한 가지 가능한 방법 :

//Heading[starts-with(., 'Ethical') and ends-with(., 'consent')] 

ends-with() 기능이 XPath는 2.0이다. XPath 1.0에서는 substring()string-length()을 사용하는 it can be replaced입니다. 다음은 동등한 XPath 1.0입니다 (가독성을 위해 포장되었습니다) :

//Heading[ 
      starts-with(., 'Ethical') 
       and 
      'consent' = substring(., string-length(.) - string-length('consent') +1) 
     ] 
관련 문제