cvs: pear /Config README.Config /Config/Config/Container xml.php

From: Date: Mon, 10 Sep 2001 08:06:18 +0000
Subject: cvs: pear /Config README.Config /Config/Config/Container xml.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-822@lists.php.net to get a copy of this message
chregu Mon Sep 10 04:06:18 2001 EDT Modified files: /pear/Config README.Config /pear/Config/Config/Container xml.php Log: new Feature (KeyAttribute) in xml-container for possibility to get a decent result if you have more than one tag with the same name on the same level Index: pear/Config/README.Config diff -u pear/Config/README.Config:1.2 pear/Config/README.Config:1.3 --- pear/Config/README.Config:1.2 Thu Aug 9 05:38:33 2001 +++ pear/Config/README.Config Mon Sep 10 04:06:18 2001 @@ -1,7 +1,7 @@ Documentation and Tutorial for PEAR-Config by Alexander Merz -$Id: README.Config,v 1.2 2001/08/09 09:38:33 cox Exp $ +$Id: README.Config,v 1.3 2001/09/10 08:06:18 chregu Exp $ A first example @@ -293,14 +293,27 @@ [key3] => value3 if you set the flag False, then [key2] will not be included. + +KeyAttribute [False] If you have 2 Blocks on the same level with the same name, + this won't work with the default settings, but you can use + the KeyAttribute flag. + Assuming the following part of a xml: + ... + <block2 name="whatever" key3="value3"/> + <block2 name="whereever" key4="value4"/> + <block2 key4="value5"/> + ... + if you set now the flag KeyAttribute to "name", you'll get + the name attribute as the key name, whereever this attribute + is set: + + $data = $conf->getValues(".../block2"); + + [whatever] => array(name=>whatever, key3=>value3) + [whereever] => array(name=>whereever, key4=>value4) + [block2] => array(key4=>value5) Limitations: - -There can't be 2 Blocks on the same level with the same name. The following will -not reasonably work: - - <block2 key2="value2" key3="value3"/> - <block2 key2="value3" key4="value4"/> Writing is not supported yet. you can't write back the changes you made. Since xml files can be written in different ways meaning almost the same, it's hard to Index: pear/Config/Config/Container/xml.php diff -u pear/Config/Config/Container/xml.php:1.2 pear/Config/Config/Container/xml.php:1.3 --- pear/Config/Config/Container/xml.php:1.2 Fri Aug 17 11:22:39 2001 +++ pear/Config/Config/Container/xml.php Mon Sep 10 04:06:18 2001 @@ -1,4 +1,4 @@ -<?php + <?php //+----------------------------------------------------------------------+ // | PHP version 4.0 | //+----------------------------------------------------------------------+ @@ -41,7 +41,8 @@ var $feature = array ("IncludeContent" => True, "MasterAttribute" => False, "IncludeMasterAttribute" => True, - "IncludeChildren" => True + "IncludeChildren" => True, + "KeyAttribute" => False ); var $tagname = "tagname"; @@ -61,7 +62,7 @@ { $this -> datasrc = $datasrc ; - $this->setFeatures($feature, array_merge($this->allowed_options, array('IncludeContent', 'MasterAttribute','IncludeMasterAttribute','IncludeChildren'))); + $this->setFeatures($feature, array_merge($this->allowed_options, array('IncludeContent', 'MasterAttribute','IncludeMasterAttribute','IncludeChildren','KeyAttribute'))); if( file_exists( $datasrc ) ) { //xmldocfile is broken in 4.0.7RC1 @@ -125,6 +126,13 @@ //this is only for the root element $parentslash ="/"; } + //if feature KeyAttribute is set and the name is an attribute in the xml, take this as key for the array + if ($this->feature["KeyAttribute"] && $element->get_attribute($this->feature["KeyAttribute"])) + { + print "here"; + $element->{$this->tagname} = $element->get_attribute($this->feature["KeyAttribute"]); + } + if ($this->feature["IncludeChildren"] ) { @@ -146,7 +154,7 @@ } } } - + if (($this->feature["IncludeContent"]|| $this->feature["MasterAttribute"] == "content") && $element->content) {

« previous php.pear.cvs (#822) next »