Enhanced XPath Support

XPath is a language allowing you to easily work with your XML documents. It’s already usable via the DOM Find XML element command and with 4D v18 R3, the support of the XPath syntax has been drastically enhanced. If you’re among those who requested features such as using a wildcard in a path, then keep reading!

To use the new syntax with existing applications, you need to check the “Use standard XPath” compatibility setting. Newly created databases use the new syntax by default. You can now use new expressions such as //, @, *, last() to simplify your searches.

Examples of writing predicates 

We’ll use the following XML document in the examples below:

<?xml version="1.0" encoding="UTF-8"?>
  <title lang="en">The Wheel of Time</title>
  <title lang="fr">La roue du temps</title>
  <title lang="en">Harry Potter</title>
  <title lang="en">Learning XML</title>
  • Find the next to last book element that is the child of the bookstore element:

$Dom_root2:=DOM Find XML element($Dom_root;"/bookstore/book[last()-1]";$arrAfound)
// Returns
// ‹title lang="en"›Harry Potter‹/title›
// ‹price›50.00‹/price›

  • Find all the title elements that have a “lang” attribute with a value of “fr”:

$Dom_root2:=DOM Find XML element($Dom_root;"//title[@lang='fr']";$arrAfound)
// Returns ‹title lang="fr"›La roue du temps‹/title›

  • Find all the book elements that have a price equal to 39.95:

$Dom_root2:=DOM Find XML element($Dom_root;"book[price=39.95]";$arrAfound)</br />
// Returns
// ‹title lang="en"›Learning XML‹/title›
// ‹price›39.95‹/price›

These are just a few examples of what you can do with the new expressions. You can mix them in a more or less complex way to find the results you need. Refer to the documentation to see what you can do with these new enhancements in more detail.

Fabrice Mainguené
• Product Owner •Fabrice Mainguené joined 4D Program team in November, 2016. As a Product Owner, he is in charge of writing the user stories then translating it to functional specifications. His role is also to make sure that the feature implementation delivered is meeting the customer need.After obtaining a Bachelor degree in Computer Science at CNAM, Fabrice joined a small software publishing company as a Windev developer. Then he worked for different companies in industry and trade areas as a Windev and web developer as well as technical advisor on new features.