University of Newcastle · FACULTY OF COMPUTER SCIENCE

SENG1050 Chap.7 Content Management, XPath and PHP Templates

- one subject, every graph, every model, every mark
8 Chapters3-page Bible
Our own words - no uploaded lecturer files
Updated for this semester
Chapter 7 of 12 · SENG1050

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.

In this chapter

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

Q [3 marks]. A shop has forty product pages that share one header, menu and footer, and each product's details live in an XML file. Name the template source, the data source and the templating engine, and say what happens when the menu changes. The mark allocation here is AskSia's own and is not a University marking scheme.
A templating system in one view: the shared template and the page-specific data both feed the engine, which combines them into the finished HTML page sent to thA templating system in one view: the shared template and the page-specific data both feed the engine, which combines them into the finished HTML page sent to the browser. Template sourcecommon parts Data sourceunique parts Templatingengine HTML page
A templating system in one view: the shared template and the page-specific data both feed the engine, which combines them into the finished HTML page sent to the browser.
  • 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.
The shared layout is the template source, the XML product file is the data source and the PHP script is the engine that merges them. A menu change is made once in the template and appears on every generated page.
Sia tip — Ask of every part of the site whether it is the same on every page or unique to one page: common parts go in the template, unique parts in the data.
Glossary

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 @*.
FAQ

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.

Study strategy

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.

A+Everything unlocked
Unlocks this Bible + all 14 of your University of Newcastle subjects - and 1,000+ Bibles across every Australian university.
Sia - your SENG1050 tutor, unlimited, worked the way the exam marks it
The full 3-page Bible + practice bank with worked solutions
Chrome extension - sync your LMS so Sia knows your deadlines
Bilingual EN / Chinese on every Bible and every Sia answer
$0.99 Trial
30-day money-back · cancel in one tap · how it works