Parsing XML With DOMXML And PHP
(Page 1 of 6 )
Extensible Mark-up Language (XML) has just about made its impression everywhere: B2B, B2C, as a replacement for .INI files, to aid with data abstraction and transportation, etc. In this article Mitchell shows us how to use the DOMXML library to parse and extract data from both local and remote XML files with PHP.Extensible Mark-up Language (XML) has just about made its impression everywhere: B2B, B2C, as a replacement for .INI files, to aid with data abstraction and transportation, etc. There are a huge number of companies that offer some sort of content over the web in the form of XML, such as news headlines, weather conditions, traffic reports, etc.
When we're talking about data manipulation and implementation with a reference to PHP, most people will automatically assume some sort of interaction with a MySQL database. MySQL has become synonymous with PHP, just like Oracle has become synonymous with Java. MySQL is great, but we can make our data more readily available over the web in the form of XML.
Two benefits of transporting data across the web in the format of XML spring into mind: its cross-platform availability, and its language-neutral syntax: as long as an XML document is available for download from a web site or FTP server, we can parse that document through PHP and then do whatever we like (subject to copyright laws) with that data.
In this article I'm going to give you the 101 on how to parse XML documents using the DOMXML library in PHP. I will discuss setting up the XML parser, loading and parsing documents. Once we've covered enough solid ground, I will show you how to implement a real-time XML feed from devArticles.com, which you can then use on your site.
To get the most out of this article and its coding samples, you should be running a Windows/Linux/Unix web server with the latest version of Apache installed. You can download Apache for Windows, Linux and Unix for free from
http://apache.org.
Because this article describes how to actually parse XML documents and not what XML is, you should have a fairly substantial knowledge of the XML language syntax already (If you don’t, then refer to some of the books at the end of this article). You should also be proficient with PHP.
Next: What is the DOMXML parsing method? >>
More PHP Articles
More By Mitchell Harper