Return to Snippet

Revision: 16017
at July 23, 2009 09:57 by mikeevans


Initial Code
function formatIFRAMECells1($oDom)
	{
		$oXpath = new DOMXpath($oDom);
		$oElements = $oXpath->query("//td[@class='tditem']");
		
		//Remove the TD element to the right of the logo cell. This xpath query finds the following TD element:
		// <td bgcolor="#FFFFFF" height="2" class="tditem"> 
		//
		// Only remove it if it's also followed by:
		//<div align="left"><img src="http://www.mobiles4everyone.com/images/horizontallineplain.jpg" width="100%" height="1"></div>
			
		if (!is_null($oElements))
		{
			foreach ($oElements as $oElement)
			{
				if($oElement->hasChildNodes())
				{
					$oChildren = $oElement->childNodes; 
					for($i=0;$i<$oChildren->length;$i++) 
					{	
						$oChild = $oChildren->item($i); 
						if($oChild->nodeName == "div")
						{
						
							if($oChild->hasChildNodes())
							{
								$oDivChild = $oChild->firstChild; 
								if($oDivChild->nodeName == "img")
								{
									$oElement->parentNode->removeChild($oElement);
									break;
								}
							}
						}
						
					}
				}
			}	
		}
		return $oDom;
	}

Initial URL


Initial Description
Manipulates XML nodes using PHP's Dom library. Includes XPath navigation, child manipulation, and deletion of current document.

Initial Title
Remove DOM Node from XML

Initial Tags
php, DOM, xml

Initial Language
PHP