Cheap Web Hosting for Developers

PHP, MySQL, Java, Unix Cheap Web Hosting

258 CHAPTER 7 SIMPLEXML The initial $sxe

Filed under: PHP and XML — webmaster @ 09:07

258 CHAPTER 7 SIMPLEXML The initial $sxe object was created using the new keyword with the extended class. As shown in the second line, the object returned from the node1 property was created using the extended class. Once the initial object based on a SimpleXMLElement class is created, all objects will be created using the same class. The new keyword is nice to use when working with XML contained in a string, but it doesn t help much when the data resides in a file. As mentioned in the earlier Creating a SimpleXMLElement Object section, the load functions take an optional class_nameparameter. This parameter indicates the class to use for creating the initial object. Using the mySXE class, you can load data from either a string or a file and have the ability to use the custom appendChild() method: $sxe = simplexml_load_string(”“, “mySXE”); $sxe->node1->appendChild(”node2″, “content”); print $sxe->asXML(); The result of this is the same as the results using the new keyword. Using Namespaces in SimpleXML Dealing with namespaced documents using SimpleXML is a bit different from handling documents without namespaces. Listing 7-2 contains the document from Listing 7-1 modified to use namespaces. Listing 7-2. Modified Document Using Namespaces: Filename sxmlns.xml Rob Richards 2005 Rob Richards If you tried to access this document using the normal methods for accessing elements and attributes, you would find out that nothing works. For example: $book = simplexml_load_file(’sxmlns.xml’); print $book[”lang”].”n”; print $book->bookinfo->title.”n”; This code prints nothing but two blank lines.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Clan Web Hosting services

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URI

Sorry, the comment form is closed at this time.

Powered by Cheap Web Hosting