Xpath XPath is a language for finding information in an XML document.
Expert Series Webinar Deep Dive Into...
Transcript of Expert Series Webinar Deep Dive Into...
![Page 1: Expert Series Webinar Deep Dive Into XPathww2.mendix.com/rs/729-ZYH-434/images/XPathWebinarSlides.pdf · ‘XPath constraint’ vs. ‘Constraint by’ }‘XPath constraint’ will](https://reader035.fdocuments.in/reader035/viewer/2022071218/60507a173792ba41737a9810/html5/thumbnails/1.jpg)
Expert Series Webinar
Deep Dive Into XPathDaniela Field – Senior Solutions Consultant
![Page 2: Expert Series Webinar Deep Dive Into XPathww2.mendix.com/rs/729-ZYH-434/images/XPathWebinarSlides.pdf · ‘XPath constraint’ vs. ‘Constraint by’ }‘XPath constraint’ will](https://reader035.fdocuments.in/reader035/viewer/2022071218/60507a173792ba41737a9810/html5/thumbnails/2.jpg)
Agenda
} What are XPaths
} XPath Syntax
} Examples
} Best Practices
![Page 3: Expert Series Webinar Deep Dive Into XPathww2.mendix.com/rs/729-ZYH-434/images/XPathWebinarSlides.pdf · ‘XPath constraint’ vs. ‘Constraint by’ }‘XPath constraint’ will](https://reader035.fdocuments.in/reader035/viewer/2022071218/60507a173792ba41737a9810/html5/thumbnails/3.jpg)
} Primary query language§ OQL is secondary query language
} Query on hierarchical structures
What is a query?
} A query is a command to obtain a specific set of data
XPath – What is it?
![Page 4: Expert Series Webinar Deep Dive Into XPathww2.mendix.com/rs/729-ZYH-434/images/XPathWebinarSlides.pdf · ‘XPath constraint’ vs. ‘Constraint by’ }‘XPath constraint’ will](https://reader035.fdocuments.in/reader035/viewer/2022071218/60507a173792ba41737a9810/html5/thumbnails/4.jpg)
} Pages§Constrain on context - (i.e. data grid)
§Constrain on selectable data - (i.e. reference selector)
} Microflows§Constrain on data retrieve
} Security§Constrain on access rights
XPath - Locations
![Page 5: Expert Series Webinar Deep Dive Into XPathww2.mendix.com/rs/729-ZYH-434/images/XPathWebinarSlides.pdf · ‘XPath constraint’ vs. ‘Constraint by’ }‘XPath constraint’ will](https://reader035.fdocuments.in/reader035/viewer/2022071218/60507a173792ba41737a9810/html5/thumbnails/5.jpg)
//Training.Registration
[Training.Registration_ScheduledCourse
/Training.ScheduledCourse
/Training.ScheduledCourse_Course
/Training.Course/Title = ‘Advanced Course']
XPath - Query on hierarchical structures
![Page 6: Expert Series Webinar Deep Dive Into XPathww2.mendix.com/rs/729-ZYH-434/images/XPathWebinarSlides.pdf · ‘XPath constraint’ vs. ‘Constraint by’ }‘XPath constraint’ will](https://reader035.fdocuments.in/reader035/viewer/2022071218/60507a173792ba41737a9810/html5/thumbnails/6.jpg)
//Training.Registration[Training.Registration_ScheduledCourse/Training.ScheduledCourse/
Training.ScheduledCourse_Course/Training.Course/Title= ‘Advanced Course']
XPath – Total XPath query
![Page 7: Expert Series Webinar Deep Dive Into XPathww2.mendix.com/rs/729-ZYH-434/images/XPathWebinarSlides.pdf · ‘XPath constraint’ vs. ‘Constraint by’ }‘XPath constraint’ will](https://reader035.fdocuments.in/reader035/viewer/2022071218/60507a173792ba41737a9810/html5/thumbnails/7.jpg)
// //Training.Course Context (managedunderthehood)
[ ] [Title = ‘Advanced Course'] GroupingofXpath
. Training.Course Separatemodule&element
/ Training.Course/Title Separate domainmodelelements
( ) [not(Title = 'Introduction Course')] Groupingoffunctions
XPath - Tokens
![Page 8: Expert Series Webinar Deep Dive Into XPathww2.mendix.com/rs/729-ZYH-434/images/XPathWebinarSlides.pdf · ‘XPath constraint’ vs. ‘Constraint by’ }‘XPath constraint’ will](https://reader035.fdocuments.in/reader035/viewer/2022071218/60507a173792ba41737a9810/html5/thumbnails/8.jpg)
}Attributes
}Entities}Associations}Variables
[Name = 'Jansen’]
[Training.Trainee/Name = 'Jansen’]
[Training.Registration_Trainee/
Training.Trainee/Name = 'Jansen’]
[Training.Registration_Trainee = $Trainee]
XPath - Elements
![Page 9: Expert Series Webinar Deep Dive Into XPathww2.mendix.com/rs/729-ZYH-434/images/XPathWebinarSlides.pdf · ‘XPath constraint’ vs. ‘Constraint by’ }‘XPath constraint’ will](https://reader035.fdocuments.in/reader035/viewer/2022071218/60507a173792ba41737a9810/html5/thumbnails/9.jpg)
} + , -
} *, div
} =, !=, <, <=, >, >=
} or, and, empty
Examples§ [Grade < 5
orGrade >= 7andTraining.Registration_Trainee/Training.Trainee/FirstName = empty]
XPath - Operators
![Page 10: Expert Series Webinar Deep Dive Into XPathww2.mendix.com/rs/729-ZYH-434/images/XPathWebinarSlides.pdf · ‘XPath constraint’ vs. ‘Constraint by’ }‘XPath constraint’ will](https://reader035.fdocuments.in/reader035/viewer/2022071218/60507a173792ba41737a9810/html5/thumbnails/10.jpg)
Return//Training.Trainee
XPath - Example Attribute value 1/3
[FirstName = ‘Tom’]
![Page 11: Expert Series Webinar Deep Dive Into XPathww2.mendix.com/rs/729-ZYH-434/images/XPathWebinarSlides.pdf · ‘XPath constraint’ vs. ‘Constraint by’ }‘XPath constraint’ will](https://reader035.fdocuments.in/reader035/viewer/2022071218/60507a173792ba41737a9810/html5/thumbnails/11.jpg)
Return//Training.Trainee
XPath - Example Association 2/3
[Training.Registration_Trainee/Training.Registration/Discount > 30]
![Page 12: Expert Series Webinar Deep Dive Into XPathww2.mendix.com/rs/729-ZYH-434/images/XPathWebinarSlides.pdf · ‘XPath constraint’ vs. ‘Constraint by’ }‘XPath constraint’ will](https://reader035.fdocuments.in/reader035/viewer/2022071218/60507a173792ba41737a9810/html5/thumbnails/12.jpg)
Return//Training.Trainee
XPath - Example Multiple Association 3/3
[Training.Registration_Trainee/Training.Registration/Discount < 30or Training.Registration_Trainee/Training.Registration/Discount >= 50]
![Page 13: Expert Series Webinar Deep Dive Into XPathww2.mendix.com/rs/729-ZYH-434/images/XPathWebinarSlides.pdf · ‘XPath constraint’ vs. ‘Constraint by’ }‘XPath constraint’ will](https://reader035.fdocuments.in/reader035/viewer/2022071218/60507a173792ba41737a9810/html5/thumbnails/13.jpg)
Modify the “ScheduledCourse_Overview, It must show the following:
Assignment 7.1.1 - XPath basics
Tab Content
Scheduled Scheduledcoursesthathavenotyetstarted
Inprogress Scheduledcoursesthatareinprogressatthemoment
Finalized Scheduledcoursesthathaveendedalready
Incomplete Scheduledcoursethathaven’ttheirfulldetailsset
All AllScheduledcourses
![Page 14: Expert Series Webinar Deep Dive Into XPathww2.mendix.com/rs/729-ZYH-434/images/XPathWebinarSlides.pdf · ‘XPath constraint’ vs. ‘Constraint by’ }‘XPath constraint’ will](https://reader035.fdocuments.in/reader035/viewer/2022071218/60507a173792ba41737a9810/html5/thumbnails/14.jpg)
} Show the following on page XPathBasic§ Unattended Registrations:
A Trainee did not attend
§ Unattended and < 50% Discount scheduled courses:A Trainee did not attend and where a discount smaller than 50%
§ Attended or No Registrations scheduled courses:A Trainee did attend or where there were no Registrations.
§ Attended, Professional and >50% Discount scheduled courses:Trainees of a Professional level attended and where a discount was bigger than 50%.
Assignment 7.1.2 - XPath basics
![Page 15: Expert Series Webinar Deep Dive Into XPathww2.mendix.com/rs/729-ZYH-434/images/XPathWebinarSlides.pdf · ‘XPath constraint’ vs. ‘Constraint by’ }‘XPath constraint’ will](https://reader035.fdocuments.in/reader035/viewer/2022071218/60507a173792ba41737a9810/html5/thumbnails/15.jpg)
} id
} contains
} start-with, ends-with
} not
} True, false
} length
} date-time functions
} Examples
§ [contains(Name, 'an')]
§ [not(Name = 'Jansen')]
§ [id = $currentUser]
XPath – Constraint functions
![Page 16: Expert Series Webinar Deep Dive Into XPathww2.mendix.com/rs/729-ZYH-434/images/XPathWebinarSlides.pdf · ‘XPath constraint’ vs. ‘Constraint by’ }‘XPath constraint’ will](https://reader035.fdocuments.in/reader035/viewer/2022071218/60507a173792ba41737a9810/html5/thumbnails/16.jpg)
Object related} [%CurrentUser%]
} [%CurrentObject%]
User role related} [%UserRole_Administrator%]
Date-Time related} [%CurrentDateTime%]
Period related} [%DayLength%]
Examples
XPath - System variables
[id = ‘[%CurrentUser%]'][System.UserRoles = ‘[%UserRole_Administrator%]'][DateRegistered >'[%BeginOfCurrentDay%] - 3 * ‘[%YearLength%]']
![Page 17: Expert Series Webinar Deep Dive Into XPathww2.mendix.com/rs/729-ZYH-434/images/XPathWebinarSlides.pdf · ‘XPath constraint’ vs. ‘Constraint by’ }‘XPath constraint’ will](https://reader035.fdocuments.in/reader035/viewer/2022071218/60507a173792ba41737a9810/html5/thumbnails/17.jpg)
Return//Training.Trainee
XPath - Example function 1/5
[not(FirstName = 'Tom')]
Which is the same as
[FirstName != ‘Tom’]
![Page 18: Expert Series Webinar Deep Dive Into XPathww2.mendix.com/rs/729-ZYH-434/images/XPathWebinarSlides.pdf · ‘XPath constraint’ vs. ‘Constraint by’ }‘XPath constraint’ will](https://reader035.fdocuments.in/reader035/viewer/2022071218/60507a173792ba41737a9810/html5/thumbnails/18.jpg)
Return//Training.Trainee
XPath - Example function 2/5
[not(Training.Registration_Trainee/Training.Registration/Discount = 30)]
Which is not the same as
[Training.Registration_Trainee/Training.Registration/Discount != 30 ]
![Page 19: Expert Series Webinar Deep Dive Into XPathww2.mendix.com/rs/729-ZYH-434/images/XPathWebinarSlides.pdf · ‘XPath constraint’ vs. ‘Constraint by’ }‘XPath constraint’ will](https://reader035.fdocuments.in/reader035/viewer/2022071218/60507a173792ba41737a9810/html5/thumbnails/19.jpg)
Return//Training.Trainee
XPath - Example function 3/5
[contains(FirstName, ‘Tom’)]
![Page 20: Expert Series Webinar Deep Dive Into XPathww2.mendix.com/rs/729-ZYH-434/images/XPathWebinarSlides.pdf · ‘XPath constraint’ vs. ‘Constraint by’ }‘XPath constraint’ will](https://reader035.fdocuments.in/reader035/viewer/2022071218/60507a173792ba41737a9810/html5/thumbnails/20.jpg)
Return//Training.Trainee
XPath - Example function 4/5
[DateOfBirth < '[%CurrentDateTime%] '- 15 * [%YearLength%]']
![Page 21: Expert Series Webinar Deep Dive Into XPathww2.mendix.com/rs/729-ZYH-434/images/XPathWebinarSlides.pdf · ‘XPath constraint’ vs. ‘Constraint by’ }‘XPath constraint’ will](https://reader035.fdocuments.in/reader035/viewer/2022071218/60507a173792ba41737a9810/html5/thumbnails/21.jpg)
Return
} All registrations of the user who triggered this microflow will be returned
//Training.Trainee
XPath - Example function 5/5
[Training.Registration_Trainee= '[%CurrentUser%]']
![Page 22: Expert Series Webinar Deep Dive Into XPathww2.mendix.com/rs/729-ZYH-434/images/XPathWebinarSlides.pdf · ‘XPath constraint’ vs. ‘Constraint by’ }‘XPath constraint’ will](https://reader035.fdocuments.in/reader035/viewer/2022071218/60507a173792ba41737a9810/html5/thumbnails/22.jpg)
} Start with the most restrictive constraint
XPath - Best practices
AllTasks
50%Tasks
10%Tasks
[Active=true()] [Date>'[CurrentDateTime]']
50%oftaskobjectstobeevaluatedagainst2ndconstrained
![Page 23: Expert Series Webinar Deep Dive Into XPathww2.mendix.com/rs/729-ZYH-434/images/XPathWebinarSlides.pdf · ‘XPath constraint’ vs. ‘Constraint by’ }‘XPath constraint’ will](https://reader035.fdocuments.in/reader035/viewer/2022071218/60507a173792ba41737a9810/html5/thumbnails/23.jpg)
} Start with the most restrictive constraint
XPath - Best practices
AllTasks
25%Tasks
10%Tasks
[Date>'[CurrentDateTime]'] [Active=true()]
25%oftaskobjectstobeevaluatedagainst2ndconstrained
![Page 24: Expert Series Webinar Deep Dive Into XPathww2.mendix.com/rs/729-ZYH-434/images/XPathWebinarSlides.pdf · ‘XPath constraint’ vs. ‘Constraint by’ }‘XPath constraint’ will](https://reader035.fdocuments.in/reader035/viewer/2022071218/60507a173792ba41737a9810/html5/thumbnails/24.jpg)
} Optimize XPath if possible
[Training.Registration_Trainee/Training.Registration/Discount < 30 orTraining.Registration_Trainee/Training.Registration/Discount >= 50]
[Training.Registration_Trainee/Training.Registration[Discount < 30 or Discount >= 50] ]
XPath - Best practices
![Page 25: Expert Series Webinar Deep Dive Into XPathww2.mendix.com/rs/729-ZYH-434/images/XPathWebinarSlides.pdf · ‘XPath constraint’ vs. ‘Constraint by’ }‘XPath constraint’ will](https://reader035.fdocuments.in/reader035/viewer/2022071218/60507a173792ba41737a9810/html5/thumbnails/25.jpg)
} Avoid ‘OR’ statement, where both sides follow an association & ‘NOT’ function with an association insideThese generates LEFT OUTER JOIN SQL queries; performance reductionSeparate retrieves with a join list operation can be quicker in certain cases.
XPath - Best practices
[Training.ScheduledCourse_Course/Training.Course/Duration >1orTraining.ScheduledCourse_Location/Training.Location/Active]
![Page 26: Expert Series Webinar Deep Dive Into XPathww2.mendix.com/rs/729-ZYH-434/images/XPathWebinarSlides.pdf · ‘XPath constraint’ vs. ‘Constraint by’ }‘XPath constraint’ will](https://reader035.fdocuments.in/reader035/viewer/2022071218/60507a173792ba41737a9810/html5/thumbnails/26.jpg)
[Training.ScheduledCourse_Location/Training.Location/Active]
XPath – Optimize “or”
[Training.ScheduledCourse_Course/Training.Course/Duration >1]
Unionlists$ScheduledCourseList & $ScheduledCourseListActive
![Page 27: Expert Series Webinar Deep Dive Into XPathww2.mendix.com/rs/729-ZYH-434/images/XPathWebinarSlides.pdf · ‘XPath constraint’ vs. ‘Constraint by’ }‘XPath constraint’ will](https://reader035.fdocuments.in/reader035/viewer/2022071218/60507a173792ba41737a9810/html5/thumbnails/27.jpg)
Pages
![Page 28: Expert Series Webinar Deep Dive Into XPathww2.mendix.com/rs/729-ZYH-434/images/XPathWebinarSlides.pdf · ‘XPath constraint’ vs. ‘Constraint by’ }‘XPath constraint’ will](https://reader035.fdocuments.in/reader035/viewer/2022071218/60507a173792ba41737a9810/html5/thumbnails/28.jpg)
} Generates XPath queries based on:§ Connected entity§ Sort parameters§ Search fields§ Additional XPath constraints (specified in the modeler)
} Calls the RetrieveList() action in the MBS with:} The generated XPath
} Retrieval schema• Specifying which attributes are required
• Minimizes data transfer
The data grid – XPath data source - retrieving a list
![Page 29: Expert Series Webinar Deep Dive Into XPathww2.mendix.com/rs/729-ZYH-434/images/XPathWebinarSlides.pdf · ‘XPath constraint’ vs. ‘Constraint by’ }‘XPath constraint’ will](https://reader035.fdocuments.in/reader035/viewer/2022071218/60507a173792ba41737a9810/html5/thumbnails/29.jpg)
The retrieve list action
Mxdatabase
MendixRichWebclient
MendixBusinessServer
1 4
2 3
1.Client->MBS Request:RetrieveList (XPath)
2.MBS->Database Request:SQLQuery(SELECT)
3.Database->MBS Answer: RecordSet
4.MBS->Client Answer: MendixObjectList
![Page 30: Expert Series Webinar Deep Dive Into XPathww2.mendix.com/rs/729-ZYH-434/images/XPathWebinarSlides.pdf · ‘XPath constraint’ vs. ‘Constraint by’ }‘XPath constraint’ will](https://reader035.fdocuments.in/reader035/viewer/2022071218/60507a173792ba41737a9810/html5/thumbnails/30.jpg)
//CRM.Customer[Name = ‘Tom’]
Xpath
SELECT Name, CityFROM CRM.CustomerWHERE Name = ‘Tom’
OQL
SELECT CRM$Customer.ID, CRM$CustomerName, CRM$CustomerCityFROM CRM$CustomerWHERE Name = ‘Tom’
SQL
Name, City
Schema
XPath to SQL
![Page 31: Expert Series Webinar Deep Dive Into XPathww2.mendix.com/rs/729-ZYH-434/images/XPathWebinarSlides.pdf · ‘XPath constraint’ vs. ‘Constraint by’ }‘XPath constraint’ will](https://reader035.fdocuments.in/reader035/viewer/2022071218/60507a173792ba41737a9810/html5/thumbnails/31.jpg)
//CRM.Order[Order_Customer = 1]
Xpath
SELECT Date, NumberFROM CRM.OrderWHERE CRM.Order/CRM.Order_Customer = 1
OQL
SELECT crm$order.id, crm$order.date, crm$order.numberFROM crm$orderWHERE crm$order.id“ IN
(SELECT c1crm$order_customer.crm$orderidFROM crm$order_customer c1crm$order_customerWHERE c1crm$order_customer.crm$customerid = 1)
SQL
Date, Number
Schema
XPath to SQL
![Page 32: Expert Series Webinar Deep Dive Into XPathww2.mendix.com/rs/729-ZYH-434/images/XPathWebinarSlides.pdf · ‘XPath constraint’ vs. ‘Constraint by’ }‘XPath constraint’ will](https://reader035.fdocuments.in/reader035/viewer/2022071218/60507a173792ba41737a9810/html5/thumbnails/32.jpg)
Drop down
} Each reference selector triggers its own RetrieveList() action
Pop up page
} reference selector will trigger its own RetrieveList() action atopening of the select page
} Avoid lots of editable reference selectors (dropdown) in one page;use wizards or lookup pages (popups)
Performance – Reference selectors
![Page 33: Expert Series Webinar Deep Dive Into XPathww2.mendix.com/rs/729-ZYH-434/images/XPathWebinarSlides.pdf · ‘XPath constraint’ vs. ‘Constraint by’ }‘XPath constraint’ will](https://reader035.fdocuments.in/reader035/viewer/2022071218/60507a173792ba41737a9810/html5/thumbnails/33.jpg)
} For each widget connected to a path, a separated retrieve will be done.
} When displaying multiple attributes of same associated object use a nested data view
Performance – Associated data
![Page 34: Expert Series Webinar Deep Dive Into XPathww2.mendix.com/rs/729-ZYH-434/images/XPathWebinarSlides.pdf · ‘XPath constraint’ vs. ‘Constraint by’ }‘XPath constraint’ will](https://reader035.fdocuments.in/reader035/viewer/2022071218/60507a173792ba41737a9810/html5/thumbnails/34.jpg)
} Data source microflowAllows the retrieve of a constrained list depending on multiple variables
‘XPath constraint’ vs. ‘Constraint by’
} ‘XPath constraint’ will be added to the database query which is performed at opening of the page (Static)
} ‘Constrained by’ will act on changes in page, which effects the result (Dynamic)i.e. when selecting a car brand only the brands’ car models should be available.
Data source – Selectable objects
![Page 35: Expert Series Webinar Deep Dive Into XPathww2.mendix.com/rs/729-ZYH-434/images/XPathWebinarSlides.pdf · ‘XPath constraint’ vs. ‘Constraint by’ }‘XPath constraint’ will](https://reader035.fdocuments.in/reader035/viewer/2022071218/60507a173792ba41737a9810/html5/thumbnails/35.jpg)
} XPath on page context§ Adds additional constraints to the query
(XPath)§ Constraints can be modified using tool
such as firebug
§ NOT Security! It’s just Usability
I.e. courses in the past or future
Data source – XPath constraint
[StartDate >='[%BeginOfCurrentDay%]‘]
[StartDate <'[%BeginOfCurrentDay%]‘]
![Page 36: Expert Series Webinar Deep Dive Into XPathww2.mendix.com/rs/729-ZYH-434/images/XPathWebinarSlides.pdf · ‘XPath constraint’ vs. ‘Constraint by’ }‘XPath constraint’ will](https://reader035.fdocuments.in/reader035/viewer/2022071218/60507a173792ba41737a9810/html5/thumbnails/36.jpg)
} Avoid having many editable reference selectors (dropdowns) in one page§ Use wizards or lookup pages (popups)
} Show multiple attributes of same associated object in a nested data view
} Avoid pages which trigger more then 5 queries
} Check if your page constraints deals with usability or security & adjust accordingly
Best practices
![Page 37: Expert Series Webinar Deep Dive Into XPathww2.mendix.com/rs/729-ZYH-434/images/XPathWebinarSlides.pdf · ‘XPath constraint’ vs. ‘Constraint by’ }‘XPath constraint’ will](https://reader035.fdocuments.in/reader035/viewer/2022071218/60507a173792ba41737a9810/html5/thumbnails/37.jpg)
Q&A