isCustomRSSElement, getElement, and the DOM Methods

Custom RSS elements can come in any shape or size. The most useful come as part of a separate RDF specification, such as the Dublin Core, but in practice many different types of custom tags are encountered.

In the near future, DOMIT! RSS will include a plugin mechanism for handling custom tags, but for the time being the DOM methods will have to suffice (please see the DOMIT! home page for help on using the DOMIT! XML parser methods).

If a Custom RSS Element (DOM Node) is encountered, you must first obtain a reference to it using the getElement method. The getElement method takes the name of the element as a parameter:


$currElement =& $parentElement->getElement($currElementName);

Once a reference to the Custom RSS Element is had, you can use the regular DOM methods to get data from it. A switch statement is particularly helpful in sorting out one node from another:


//simple RSS element
if ($parentElement->isSimpleRSSElement($currElementName)) { 
	//process simple element
}
//custom RSS element
else if ($parentElement->isCustomRSSElement($currElementName)) { 
	//get a reference to the current element
	$currElement =& $parentElement->getElement($currElementName);
	
	switch ($currElementName) {
		case 'dc:creator':
			echo $currElementName . ': ' . 
				$currElement->firstChild->nodeValue();
			break;
			
		case 'cost':
			echo $currElementName . ': ' . 
				$currElement->firstChild->nodeValue . 
				' ' . $currElement->getAttribute('currency');
			break;
	}
}


Documentation generated by ClassyDoc, using the DOMIT! and SAXY parsers.
Please visit Engage Interactive to download free copies.