SENG1050 Chap.7 Content Management, XPath and PHP Templates
Content Management, XPath and PHP Templates
This chapter follows the Week 7 lecture on scaling a site. It explains what a content management system does, the roles of the content management application and the content delivery application, and why templates separate shared layout from page data.
It then teaches XPath paths, predicates, wildcards and functions on a small XML file, and shows how PHP loads XML, selects nodes, loops over them and prints HTML inside a template. The lab that follows builds a simple PHP template and a page that reads an XML data file chosen through the query string, which completes the first milestone of the second web assignment.
What this chapter covers
- 01
Why sites need content management
- 02
Five CMS functions
- 03
CMA versus CDA
- 04
Template source, data source and engine
- 05
XPath paths and predicates
- 06
Wildcards and XPath functions
- 07
SimpleXML loading and selecting
- 08
Writing back to XML
Worked example · free
Identify the parts of a templating system
- 1The template source is the shared HTML holding the header, menu and footer with placeholders for product details.
- 1The data source is the XML file of product details; the templating engine is the PHP code that combines the two into each page.
- 1Changing the menu once in the template changes it on all forty pages the next time they are generated.
Key terms
- Content management system
- A content management system is an application that manages the creation, update, viewing, archiving and deletion of web content.
- Content management application
- The content management application is the administrative back end where authorised users create and change content.
- Content delivery application
- The content delivery application is the public front end that compiles content into pages and has read-only access to data.
- XPath
- XPath is a language for selecting elements and attributes in an XML document by path.
- Predicate
- A predicate is a condition in square brackets that filters the nodes an XPath step selects, such as [1] or [@rating].
- Templating engine
- A templating engine is the program that combines a shared template with page-specific data to output HTML.
- Wildcard
- A wildcard in XPath matches any element with * or any attribute with @*.
Content Management, XPath and PHP Templates FAQ
What is the difference between the CMA and the CDA?
The content management application is the back end where authorised users create and edit content, usually behind an admin directory that should be renamed. The content delivery application is the public front end that compiles content into pages from templates, caches them and only reads data.
Why do I need [0] after an xpath() call in PHP?
The xpath() method always returns an array of matching nodes, even when only one node matches. Taking element [0] gives the first node itself, which you can then cast or print. Remember that PHP arrays count from 0 while XPath positions count from 1.
What does a double slash mean in XPath?
A double slash searches for matching nodes at any depth below the current point, while a single leading slash starts an absolute path from the root. So //title finds every title in the document, wherever it is nested.
What is the principle of least privilege in a CMS?
Each user receives only the minimum access their job requires. An author might edit pages but not publish them or manage other users. Limiting access this way reduces the damage a mistake or a stolen account can cause in a large, multi-author site.
How can a PHP template choose which XML file to load?
It can read a value from the query string, such as $_GET["name"], and build the file path from it, so one script serves many pages. The lecture combines this with simplexml_load_file to load the chosen data file and print it inside the shared layout.
Exam move
Write a small XML file of your own with a repeated element, an attribute and nested children, then write ten XPath expressions against it and predict each result before checking. Next write the PHP that loads it and prints a list, using foreach, the arrow operator and an attribute. Rehearse the CMA and CDA roles as a two-column answer.
Remember the off-by-one trap: positions count from 1 in XPath but indexes count from 0 in PHP arrays.
Working through Content Management, XPath and PHP Templates in SENG1050? Sia is AskSia’s AI Computer Science tutor — ask any SENG1050 Content Management, XPath and PHP Templates question and get a clear, step-by-step explanation grounded in how SENG1050 is taught and assessed. Read this chapter free, then take your hardest questions to Sia.