format_rss_channel() and format_rss_item() both have an $args argument for extra xml tags, but only format_rss_item() has a syntax for having XML attributes. With format_rss_channel(), you can only do <key>value</key> style tags. The attributes are useful for example for doing openSearch extensions to RSS/Atom.

The way the code was written, the two functions had their own code for converting the given $args array into XML. So I took the more flexible version format_rss_item() and moved it to new a function format_xml_tags() which is now used from both. I also tweaked it to support nesting of tags (one line change).

The best part is that it's a generic function for output clean, safe XML that can be reused by contrib.

It should definitely go into HEAD, but the lack of rss channel attributes is IMO a bug in the 4.7 implementation.

CommentFileSizeAuthor
#3 xmlapi_0.diff2.55 KBSteven
xmlapi.diff1.92 KBSteven

Comments

walkah’s picture

big fat +1 . yay for more and better xml handling tools in core.

morbus iff’s picture

Subscribing. Talked to UnConeD about some changes in IRC.

Steven’s picture

StatusFileSize
new2.55 KB

Renamed format_xml_tags() to format_xml_elements() (morbus) and added doxygen for the array format (which should've been there already).

moshe weitzman’s picture

cool .. could this be used for regular HTML such as needed at http://drupal.org/node/2039 (support arbitrary nesting of lists in theme_item_list())?

Steven’s picture

Status: Needs review » Fixed

Forgot to mark as fixed when committed.

Anonymous’s picture

Status: Fixed » Closed (fixed)