PHP, Web Programming

More features for Extending SimpleXML

<![CDATA[I've added two new public static function to ExtendXML.
The first one is registerTagClass. This takes two arguments, the first is a tag name and the second is a class (that extends ExtendXML. This will make all children of that tag name become that class instead.
The second is registerTagCallback. This takes one argument, a callback. That callback must take one argument, a tag name and must return the class (as a string) that those tags should become.

If for example you were parsing HTML and you wanted all paragraph p tags to be handled by ParagraphXML, you could use:
ExtendXML::registerTagClass('p', 'ParagraphXML');

A word of warning, it’s case sensitive. If a callback is registered this will be used regardless of any calls to registerTagClass.

If you’ve never used callbacks before, they take one of three forms. Either a string that is the name of a function, an array with the first element a class name (as a string) and the second element a static method of that class (as a string) or finally, as an array with the first element an object and the second element a method of that object.

EXML, ExtendXML, SimpleXML, XML, parsing XML, PHP5, callbacks, programming, coding, parsing HTML, OOP]]>

Advertisements

2 thoughts on “More features for Extending SimpleXML

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s