Cheap Web Hosting for Developers

PHP, MySQL, Java, Unix Cheap Web Hosting

268 CHAPTER 7 SIMPLEXML application, so it

Filed under: PHP and XML — webmaster @ 05:29

268 CHAPTER 7 SIMPLEXML application, so it assumes all incoming arrays contain locations and values for the PAD template. The setValue() function is recursive. As long as the value of the array is another array, the function calls itself with the $sxe variable pointing to the field name passed into the function, the new field name, and the new field value. Once the incoming value is no longer an array, it is set as the value of the new field passed to the function of the $sxe object passed into the function. The value is also encoded using htmlentities() to ensure the data will be properly escaped. For instance, a value containing the & character needs it converted to its entity format, &. The last use of SimpleXML worth mentioning in this application is within the validatePAD() function. PAD contains a RegEx field within each Field node of the specification. This field defines the regular expression the data needs to conform to in order to be considered valid. The same technique is used to loop through the specification file to find the RegEx node and the Path node, as you have seen in other functions in this application. The correct element is also navigated to within the template using similar techniques. Once you ve gathered all the information, you can test the regular expression against the value of the $sxe element from the working template. This example illustrated how you can use XML and SimpleXML to generate an application including its UI, data storage, and validation rules using a real-world case. If you are a current shareware author, you may already be familiar with the PAD format. Using techniques within this application, you should have no problems writing your own application to generate your PAD files. In any case, this example has shown that even though SimpleXML has a simple API and certain limitations, you can use it for some complex applications, even when you don t know the document structure. Conclusion The SimpleXML extension provides easy access to XML documents using a tree-based structure. The ease of use also results in certain limitations. As you have seen, elements cannot be created; only elements, attributes, and their content are accessible, and only limited information about a node is available. This chapter covered the SimpleXML extension by demonstrating its ease of use as well as its limitations. The chapter also discussed methods of dealing with these limitations, such as using the interoperability with the DOM extension and in certain cases with built-in PHP object functions. The material presented here provides an in-depth explanation of SimpleXML and its functionality; the examples should provide you with enough information to begin using SimpleXML in your everyday coding. The next chapter will introduce how to parse streamed XML data using the XMLReader extension. Processing XML data using streams is different from what you have dealt with to this point because unlike the tree parsers, DOM and SimpleXML, only portions of the document live in memory at a time.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost PHP MySQL 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