1

I have the following xpath match in my soapui test suite ,

//html/body/div[2]/table/tbody/tr[td/b[text()='NewsV1']]//td[4]/a[1]/@href[1]

Result :

http://shortness.com:101115/localnewsv1/info

I want the expected result as below (it should take the result from http to till the third /)

http://shortness.com:101115/

I have tried the following xpath combined with regular expression

tokenize(/html/body/div[2]/table/tbody/tr[td/b[text()='NewsV1']]//td[4]/a[1]/@href[1], ' ' )[matches(., 'http://+w[a-zA-Z0-9.]+d{*}+/')

This gives me an invalid expression in the result.if you have idea point the issue or suggest.

Screenshot for the issue

2
  • Try regex101.com/r/F1plDY/1 Commented Feb 12, 2018 at 14:36
  • i am still getting the same error as invalid expression .it may be problem with the syntax i tried for tokenize.can you please align the syntax inside the xpath i given. xpath i tried now, tokenize(//html/body/div[2]/table/tbody/tr[td/b[text()='NewsV1']]//td[4]/a[1]/@href[1], ' ')[matches(., 'http:\/{2}[^\/]+\/')] Commented Feb 12, 2018 at 15:12

2 Answers 2

1

For this markup,

<a href="http://shortness.com:101115/localnewsv1/info"/>

this XPath 2.0 expression (make sure your library supports XPath 2.0),

concat(join(tokenize(/a/@href, '/' )[position() < 4],'/'),'/')

will return

http://shortness.com:101115/

as requested.

Sign up to request clarification or add additional context in comments.

3 Comments

i am getting the result as invalid xpath expression for the below xpath, concat(join(tokenize(added the xpath for fetching the markup, '/' )[position() < 4],'/'),'/')
Then your XPath processor doesn't support XPath 2.0. I suggest that you find one that does -- string manipulation is painful in XPath 1.0. Note that matches() also requires XPath 2.0, so you won't be able to use regex either.
i tried the concat method with below expression concat(//html/body/div[2]/table/tbody/tr[td/b[text()='NewsSV1']]//td[4]/a[1]/@href[1],'_',//html/body/div[2]/table/tbody/tr[td/b[text()='NewsV1']]//td[4]/a[1]/@href[1]) will return shortness.com:101115 gives two times in the result so i feel concat is working then obviously some chances there i have xpath 2.0
1

I guess that d{*} might have a meaning in some regex dialects but it has no meaning (and is invalid) in the XPath 2.0 regex dialect.

3 Comments

yeah can you give some example of xpath+regular expression.i am not able to find any link exactly.
There's a whole chapter on regular expressions in my book (XSLT 2.0 and XPath 2.0 Programmer's Reference). But if you don't want to pay for it, you can read the spec. You'll need w3.org/TR/xpath-functions-31 section 5.6.1, which defines XPath regular expressions in terms of differences from XSD regular expressions, which in turn are described in w3.org/TR/xmlschema11-2 appendix H.
the document you shared very useful.just now saw your link and started reading that immediately after seeing this.lot more to learn and understand.so far i can use replace function(my string ,my string pattern,expeceted string pattern) I believe this will work let me try

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.