xml - XPath: Search for several nodes in specific order -
i have xml file "hello" nodes containing "word" nodes:
<doc> <hello> <word>hello</word><word>world</word><word>!</word> </hello> <hello> <word>hello</word><word>!</word><word>world</word> </hello> <hello> <word>hello</word><word>world</word><word>!</word><word>blorf</word> </hello> <hello> <word>hello</word><word>wo</word><word>rld!</word> </hello> </doc> i want match first hello. second 1 has wrong order, , third 1 has word. fourth has right text, divided words incorrectly.
this query works in xpath 1.0 extremely wordy. there simpler way?
//hello[count(word) = 3 , word[1] = "hello" , word[2] = "world" , word[3] = "!"] this works in xpath 2.0. there way equivalent in xpath 1.0?
//hello[deep-equal(data(subsequence(word,1)),('hello','world','!'))]
if you're using xpath 2.0, can use string-join() add delimiter separate individual words.
//hello[string-join(word,'|')='hello|world|!'] you may need use normalize-space(word) if white-space supposed ignored.
another xpath 2.0 alternative use deep-equal() compare 2 sequences. safer because it's not using delimiter might part of text value.
//hello[deep-equal(data(subsequence(word,1)),('hello','world','!'))]
Comments
Post a Comment