|
|
#1 (permalink) |
|
Status: Junior Member
Join Date: Oct 2008
Posts: 12
|
SimpleXML uses a built-in class called SimpleXMLElement. It converts an XML document into a simpleXMLElement object. This contains an array of all the element, text, and attribute nodes, each of which is, in turn, a SimpleXMLElement object. What makes it so easy to use is that the name of each node becomes a property of the object, giving you direct access to it.
First, you need to load the XML document that you want to process. There are several ways of doing this, depending on whether the XML document is stored as a physical file (either locally or on a remote server) or as a string (e.g., after using the Pos_RemoteConnector). Loading XML from a file The easiest way to load an XML document from a file is to use the simplexml_load_file() function. This requires a single argument: a string containing either the path to a local file or the URL of the file on a remote server. You use it like this: $xml = simplexml_load_file($location); Alternatively, you can use the SimpleXMLElement class constructor. When used with a file, it requires two extra arguments, in addition to the file’s path or URL, like this: $xml = new SimpleXMLElement($location, null, true); . The second argument sets Libxml parameters (see PHP: Predefined Constants - Manual), which are rarely used. Even though you don’t normally want them, the argument needs to be set to null because the third argument is required when the XML document is stored as a physical file, rather than a string. The third argument is a Boolean value that needs to be set to true. There’s no advantage to using the SimpleXMLElement constructor unless you need the advanced features offered by the Libxml parameters. Keep things simple by using simplexml_load_file(). |
|
|
|
![]() |
| Bookmarks |
| Tags |
| document, php, simplexml, xml |
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Problem with loading the User’s profile. | prem | Windows xp Support | 1 | 02-23-2009 11:53 AM |
| Error while loading OS? | crazy | Vista Support | 1 | 02-20-2009 09:12 AM |
| How to create MS-DOS boot loading CD? | bubli | Vista Support | 1 | 02-18-2009 08:51 AM |
| Loading Variables in Flash | genius4ever | Graphics | 0 | 11-11-2008 11:40 AM |
| Loading classes automatically in PHP | crazy4ever | Programming | 0 | 11-04-2008 10:24 AM |