Re: Prevent XSS using DOM Extension and/or SimpleXML

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Raphael Martins wrote:

But I don´t know how to loop over every attribute for each tag in the DomTree.

Not sure if you need to do this element by element or just want all attributes, but here are two ways using DOM. They assume $dom is an already loaded DOMDocument.

1 - Use XPath:

$xPath = new DOMXPath($dom);
$nodelist = $xPath->query("//@*");
foreach ($nodelist AS $attr) {
	print $attr->nodeName." ".$attr->nodeValue."\n";
}


2 - Walk the tree manually:

function checkElement($node) {
	$attlist = $node->attributes;
	foreach ($attlist AS $attr) {
		print $attr->nodeName." ".$attr->nodeValue."\n";
	}
	if ($node->hasChildNodes()) {
		foreach ($node->childNodes AS $child) {
			if ($child->nodeType == XML_ELEMENT_NODE) {
				checkElement($child);
			}
		}
	}
}

$root = $dom->documentElement;
checkElement($root);

Rob

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux