EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Software Development Software Development Tutorials XML Tutorial XPath Matches
 

XPath Matches

Updated March 28, 2023

XPath Matches

 

 

Definition of XPath Matches

XPath matches allow us to use an expression of XPath for selecting content from the target request or the response node for comparing the value which we expect. The matches are applied to the requests and responses from the xml data in the body. Ready API is not parsing the xml documents which contain the character of byte order mark for the XPath match expression.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

What is XPath matches?

The standard of W3C for the XQuery 1.0 and XPath 2.0 operator and function will be defining the three functions i.e. replace, match and tokenize which take a regular expression as parameters. The XPath and xquery standard will introduce the new regular expressions, it is identical to the xml schema by using additional features of the modern flavors of regex. All the valid xml schema is valid for the XPath regex. Feature of xml schema is used in a validity test, this feature will eliminate from the performance reasons, XPath function is performing the more complex regular expressions.

XPath Matches Function

  • The matches function is returning the true if the supplied string will match the given regular expressions. Below is the signature of the XPath matches function is as follows.

Signatures –

Fn : matches (
$input as xs : string?,
$pattern as xs : string
) as xs : boolean
Fn : matches (
$input as xs : string?,
$pattern as xs : string,
$flags as xs : string
) as xs : boolean
  • The function is context-independent focused independent and deterministic. Basically, the effect of calling this first version of the function is the same as the effect of calling the second version with the argument of $flags for setting it to the zero-length string.
  • Matches function flags are defined in a @input in the sequence of empty, and it was interpreted as a string of zero length.
  • The function of matches is returning a true if the $input or another substring of $input will match the regular expression which was supplied by using $pattern. Otherwise, the function of matches will return false.
  • The matching rule of matches function will influenced by the value as $flags if it is present.
  • Below is the example of matches function are as follows.

Example –

fn : matches ("abcpqrxyz", "pqr") returns true()
fn : matches ("abcpqrxyz ", "^a.*a$") returns true()
fn : matches ("abcpqrxyz ", "^pqr") returns false()

1-1

  • The following function call will produces the results as follows. By using the element of poem in a context node.

Example –

fn : matches ($ABC, "pqr.*xyz") returns false()
fn : matches ($ABC, "pqr.*xyz", "s") returns true()
fn : matches ($ABC, "^pqr.*PBC,$", "m") returns true()
fn : matches ($ABC, "^pqr.*PBC,$") returns false()
fn : matches ($ABC, "kiki", "i") returns true()

1-2

  • In the XPath matched function the dynamic error will be raised if the value of the $pattern is invalid as per the rule described in the XPath matches function.
  • In the XPath matched function the dynamic error will be raised if the value of $flags is invalid as per the rule described in the XPath matches function.
  • In XPath, the matches function the meta characters ^ and $ is used as anchors and the string is used to consider as pattern matching if any substring will matches a pattern. Basically, anchors are used to starting and end of the string of used to start and end of the line. We can say that it is different from the pattern behavior where the regular expression will anchor implicitly.
  • Matching of regular expression is defined on the basis of points of Unicode it will take no account with collations.

XPath Matches Method

  • XPath matches method will be determining whether the current node will match the specified expression of system xml XPath.
  • Below is the method of XPath match are as follows, XPath matches method contains the two methods.
  • Matches (string) – This method will determine whether the current node will match the specified XPath expression or not. This method is taking the input as a string value.
  • This method contains the XPath expression as a parameter. It will return the boolean as a true value while matching the current node XPath expression otherwise it will return the false value. Below is the example of matched methods as follows.

Code –

<?xml version = "1.0" encoding = "utf-8" ?>
<School>
<stud name = "ABC" addr = "Pune" std = "4th">
<phone_no> 1234567890 </phone_no>
<school_info>
<school-name> International school </school-name>
<school_addr> Mumbai </school_addr>
</school_info>
</stud>
</school>

XPath Matches 1-3

  • Matches (XPathExpression) – This method will determine whether the current node will match the specified XPath expression or not. This method is taking the input as an XPath expression value. Basically, this method will determine whether the current node will match the specified expression of XPath.
  • Below is the example of matches method in XPath expression as follows.

Code –

<?xml version = "1.0" encoding = "utf-8" ?>
<Organization>
<Employee name = "ABC" addr = "Pune">
<phone_no> 1234567890 </phone_no>
<company_info>
<name> PQR </name>
<addr> Mumbai </addr>
</company_info>
</Employee>
<Employee name = "PQR" addr = "Mumbai">
<phone_no> 1234567890 </phone_no>
<company_info>
<name> ABC </name>
<addr> Pune </addr>
</company_info>
</Employee>
<Employee name = "XYZ" addr = "Chennai">
<phone_no> 1234567890 </phone_no>
<company_info>
<name> CBD </name>
<addr> Chennai </addr>
</company_info>
</Employee>
</Organization>

XPath Matches 1-4

Matches XPathExpression

  • The matches XPath expression will be determining the current node of the specified expression.
  • The XPath expression will contain the compiled expression of XPath. It will contain the expr as parameter values.
  • The XPath expression will be returning the Boolean value which was true, if the current node will match the expression of XPath otherwise it will return a false value.
  • In XPath expression, we cannot evaluate the argument expression if the XPath expression is not valid.
  • Below is the example of the XPath expression as follows.

Code –

<?xml version = "1.0" encoding = "utf-8" ?>
<Student>
<Stud name = "ABC" addr = "Mumbai">
<phone_no> 1234567890 </phone_no>
<stud_info>
<name> PQR </name>
<addr> Mumbai </addr>
</stud_info>
</Stud>
<Stud name = "PQR" addr = "Mumbai">
<phone_no> 1023456789 </phone_no>
<stud_info>
<name> ABC </name>
<addr> Pune </addr>
</stud_info>
</Stud>
</Student>

XPath Matches 1-5

Conclusion

The XPath and xquery standard will introduce the new regular expressions, it is identical to the xml schema. XPath matches allow us to use an expression of XPath for selecting content from the target request or the response node for comparing the value which we expect.

Recommended Articles

This is a guide to XPath Matches. Here we discuss the Definition, What is XPath matches, and examples with code implementation respectively. You may also have a look at the following articles to learn more –

  1. XPath regex
  2. XPath namespace
  3. Scrapy XPath
  4. XPath contains

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW