Skip to content

Explore XPath expressions with detailed examples for navigating XML documents. Enhance your querying skills efficiently. Contributions welcome!

Notifications You must be signed in to change notification settings

mrugeshsha15/xpath-examples-documentation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 

Repository files navigation

XPath Examples Documentation

Overview

This README provides detailed documentation on using XPath expressions for navigating XML documents. It covers various axes relationships and dynamic element selection techniques using XPath.

Table of Contents

XPath Axes: Preceding and Following

These XPath expressions allow traversal of nodes relative to a specified reference node (Node1) based on their positional relationship (preceding or following) within the document structure.

Syntax Examples

  • //Node1/preceding::*
  • //Node1/preceding-sibling::*
  • //Node1/following::*
  • //Node1/following-sibling::*

XPath Axes: Ancestor and Descendant Relationship

These expressions enable traversal between ancestor and descendant nodes relative to the reference node (Node1) within the XML document hierarchy.

Syntax Examples

  • //Node1/ancestor::*
  • //Node1/descendant::*

XPath Axes: Parent and Child Relation

These expressions facilitate navigation between parent and child nodes relative to the specified reference node (Node1) within the XML document structure.

Syntax Examples

  • //Node1/child::*
  • //Node1/parent::*

Dynamic Elements: Elements with Dynamic Property-Values and/or Text

These expressions demonstrate dynamic element selection criteria utilizing various operators such as 'and', 'or', 'contains', and 'starts-with' to match elements based on their attributes and text content.

Syntax Examples

  1. Using 'and' Operator

    • //TagName[@Att1='Value1' and @Att2='Value2']
    • //TagName[@Att='Value' and Text()='Value']
  2. Using 'or' Operator

    • //TagName[@Att1='Value1' or @Att2='Value2']
    • //TagName[@Att='Value' or Text()='Value']
  3. Using 'contains'

    • //TagName[contains(@Att,'Partial Value')]
    • //TagName[contains(text(),'Partial Value')]
  4. Using 'starts-with'

    • //TagName[starts-with(@Att,'Starting Value')]
    • //TagName[starts-with(text(),'Starting Value')]
  5. Hybrid

    • //TagName[contains(@Att1,'Partial Value') and starts-with(text(),'Starting Value')]
    • //TagName[@Att1='Value' or starts-with(@Att2,'Starting Value')]
    • //*[@Att='Value']

Usage

This documentation serves as a comprehensive reference for understanding and utilizing XPath expressions effectively in XML document processing. It can be used by developers, testers, and individuals working with XML documents to enhance their XPath querying skills.

Contributing

Contributions to improve this documentation are welcome! If you have suggestions or find errors, please feel free to open an issue or create a pull request.

License

This documentation is licensed under the MIT License. Feel free to use, modify, and distribute it for any purpose.

About

Explore XPath expressions with detailed examples for navigating XML documents. Enhance your querying skills efficiently. Contributions welcome!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published