Feeds

Harness XML with PHP 5 extensions

A time to query

SANS - Survey on application security programs

Create a PHP script, validateXML.php. Create a DOMDocument object and load the XML document. Validate the XML document with the XML schema using schemaValidate().

$isValid=$domDocument->schemaValidate("file://C:/PHP/catalog.xsd");

The output from the PHP script is as follows.

XML Document is valid

Query XML with SimpleXML

PHP 5 provides the SimpleXML extension to select XML document nodes and node values with property selectors and array iterators. To select nodes and output node values in the XML document using the SimpleXML extension create a PHP script, simpleXML.php. The SimpleXML extension provides functions simplexml_load_file(string filename) and simplexml_load_string(string xmlDocument) to load an XML document from a file or a string.

$simplexml=simplexml_load_file("file://C:/PHP/catalog.xml");

The simplexml_load_file() converts the XML document to an object of type SimpleXMLElement, and returns the root element in the XML document. As an example, output the value of the title element of the article in the first journal element.

print $simplexml->journal->article->title;

As the $simplexml object represents the root element in the XML document parsed, the value of the title attribute in the root element, catalog, is obtained as shown below.

print   $simplexml['title'];

The attributes of an element may be output using attributes(). For example, obtain the attributes in the root element.

$attributes=$simplexml->attributes();

Output the publisher attribute.

print $attributes['publisher'];

The output is shown below.

The Java XPath API
XML Zone
IBM developerWorks

3 Big data security analytics techniques

Next page: Transform XML

More from The Register

next story
OpenBSD founder wants to bin buggy OpenSSL library, launches fork
One Heartbleed vuln was too many for Theo de Raadt
Got Windows 8.1 Update yet? Get ready for YET ANOTHER ONE – rumor
Leaker claims big release due this fall as Microsoft herds us into the CLOUD
This time it's 'Personal': new Office 365 sub covers just two devices
Redmond also brings Office into Google's back yard
Ubuntu 14.04 LTS: Great changes, but sssh don't mention the...
Why HELLO Amazon! You weren't here last time
Patch iOS, OS X now: PDFs, JPEGs, URLs, web pages can pwn your kit
Plus: iThings and desktops at risk of NEW SSL attack flaw
Next Windows obsolescence panic is 450 days from … NOW!
The clock is ticking louder for Windows Server 2003 R2 users
Batten down the hatches, Ubuntu 14.04 LTS due in TWO DAYS
Admins dab straining server brows in advance of Trusty Tahr's long-term support landing
Red Hat to ship RHEL 7 release candidate with a taste of container tech
Grab 'near-final' version of next Enterprise Linux next week
Apple inaugurates free OS X beta program for world+dog
Prerelease software now open to anyone, not just developers – as long as you keep quiet
prev story

Whitepapers

Securing web applications made simple and scalable
In this whitepaper learn how automated security testing can provide a simple and scalable way to protect your web applications.
3 Big data security analytics techniques
Applying these Big Data security analytics techniques can help you make your business safer by detecting attacks early, before significant damage is done.
The benefits of software based PBX
Why you should break free from your proprietary PBX and how to leverage your existing server hardware.
Mainstay ROI - Does application security pay?
In this whitepaper learn how you and your enterprise might benefit from better software security.
Combat fraud and increase customer satisfaction
Based on their experience using HP ArcSight Enterprise Security Manager for IT security operations, Finansbank moved to HP ArcSight ESM for fraud management.