getAttribute()
Brought to you by:
bs_php,
nigelswinson
From: Philipp L. <le...@hi...> - 2002-04-19 07:39:56
|
I put my little own getAttribute() function in the class. Did I miss something or is there really only getAttributes(), and if there's no attribute of that kind available it causes an error? That were my experience with v2.20. Well I use a DTD to my XML that even expands some attributes to a value if none is given but I guess DTDs aren't parsed. Another question, how can/ should I comment the class now that I did a little change? I tried to scan the mozilla license for some information. I hope it's not illegal to redistribute the class inside my package (it's not the core, I just use it for the free QML-interpreter at http://questml.com ). My own function actually returns not null but an empty string if the attribute is not found, which I think is not really standard but very nice for my own purpoes. Now in case it's not a workaround for something that's already in the class here goes my source (just as reference with no intend to have it in any "official" version). function getAttribute($absoluteXPath, $attributeName) { $attributeValue = ""; $attributes = $this->getAttributes($absoluteXPath); foreach ($attributes as $key => $value) { if ($key == $attributeName && $attributeValue == "") $attributeValue = $value; } return $attributeValue; } |