Re: [PHP] DOM recursion

2009-03-10 Thread Jochem Maas
please keep replies on list ... I enjoy my
beatings in public ...

Joanne Lane schreef:
 On Tue, 2009-03-10 at 01:05 +0100, Jochem Maas wrote:
 
 yeah but those from php-women should know better :-)
 my eye keeps picking up php-women since I had a very nice chat
 with JRF (of phpwomen.org) at phpuk.
 
 Hi Jochem,
 I am sorry I did not get back to you earlier, as my 'weekend' is Monday
 and Tuesday.

sorry for what? and what's a weekend?

 Please do not let this reflect poorly on phpwomen as they have been a

did you notice the smiley?

 great help to me in starting PHP and your help led me to the final
 solution to get my code working as I needed, and I thank you for that.
 
 In future I will refrain from asking on this list and stay with the
 forums. 

why? this list beats any forum hands down :-)

we have Pedantic Rob, the-guy-that-wrote-the-da-vinci-code,
somone whose been programming since they were doing it with Rocks[tm]
and a concentration of other high class php-wizards you won't find anywhere
else outside of the internals group.

... oh and there's me. but you can't have everything.

granted the humor's a little whack but you get used to it, before
you know it 'your one of them'.

 Thank you again for you guidance

no problem. :-)

 J
 


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



Re: [PHP] DOM recursion

2009-03-09 Thread Jochem Maas
Jochem Maas schreef:
 Joanne Lane schreef:
 I am trying to create a class that recursively iterates over an array an
 creates XML tree to reflect a multidimensional array.
 I am not really a PHP coder, but am trying my hand.
 
 I've seen 'real coders' write stuff thats leagues worse.
 
 This is what I have so far.
 http://pastie.org/private/w75vyq9ub09p0uawteyieq

 I have tried a few methods, but I keep failing.
 Currently, all elements are appended to the root node.
 

.. yes my pleasure, glad I could help, not a problem. phffft.

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



Re: [PHP] DOM recursion

2009-03-09 Thread Nathan Rixham

Jochem Maas wrote:

Jochem Maas schreef:

Joanne Lane schreef:

I am trying to create a class that recursively iterates over an array an
creates XML tree to reflect a multidimensional array.
I am not really a PHP coder, but am trying my hand.

I've seen 'real coders' write stuff thats leagues worse.


This is what I have so far.
http://pastie.org/private/w75vyq9ub09p0uawteyieq

I have tried a few methods, but I keep failing.
Currently, all elements are appended to the root node.


.. yes my pleasure, glad I could help, not a problem. phffft.


all too often the case man, I'm sure free-w...@lists.php.net points here

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



Re: [PHP] DOM recursion

2009-03-09 Thread Jochem Maas
Nathan Rixham schreef:
 Jochem Maas wrote:
 Jochem Maas schreef:
 Joanne Lane schreef:
 I am trying to create a class that recursively iterates over an
 array an
 creates XML tree to reflect a multidimensional array.
 I am not really a PHP coder, but am trying my hand.
 I've seen 'real coders' write stuff thats leagues worse.

 This is what I have so far.
 http://pastie.org/private/w75vyq9ub09p0uawteyieq

 I have tried a few methods, but I keep failing.
 Currently, all elements are appended to the root node.

 .. yes my pleasure, glad I could help, not a problem. phffft.
 
 all too often the case man, I'm sure free-w...@lists.php.net points here

yeah but those from php-women should know better :-)
my eye keeps picking up php-women since I had a very nice chat
with JRF (of phpwomen.org) at phpuk.

oh well it was a nice little exercise in DOM, something I
haven't fully mastered yet.

 


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



[PHP] DOM recursion

2009-03-05 Thread Joanne Lane
I am trying to create a class that recursively iterates over an array an
creates XML tree to reflect a multidimensional array.
I am not really a PHP coder, but am trying my hand.
This is what I have so far.
http://pastie.org/private/w75vyq9ub09p0uawteyieq

I have tried a few methods, but I keep failing.
Currently, all elements are appended to the root node.

How can I fix this so that the XML tree, correctly reflects the array
tree.

TIA
J

-
http://www.phpwomen.org/


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



Re: [PHP] DOM recursion

2009-03-05 Thread Jochem Maas
Joanne Lane schreef:
 I am trying to create a class that recursively iterates over an array an
 creates XML tree to reflect a multidimensional array.
 I am not really a PHP coder, but am trying my hand.

I've seen 'real coders' write stuff thats leagues worse.

 This is what I have so far.
 http://pastie.org/private/w75vyq9ub09p0uawteyieq
 
 I have tried a few methods, but I keep failing.
 Currently, all elements are appended to the root node.

line 44 is the issue (kind of), you're always adding to the root node, 
regardless of 'level'
the createNode func needs a little extra something, I played with it for a few 
minutes
and come up with this .. probably not exactly what you need but it might offer
a little inspiration (not I also changed the form of the input array a little):

?php


class array2xml extends DomDocument
{

private $xpath;

private $root;

public function __construct($arr, $root='root')
{
parent::__construct();

/*** set the encoding ***/
$this-encoding = ISO-8859-1;

/*** format the output ***/
$this-formatOutput = true;

/*** create the root element ***/
$this-root = $this-appendChild($this-createElement( $root ));

$this-xpath = new DomXPath($this);
}

/*
* creates the XML representation of the array
*
* @accesspublic
* @paramarrayThe array to convert
*/


public function createNode( $arr, $node = null)
{
if (is_null($node))
$node = $this-root;

foreach($arr as $element = $value) {
if (is_numeric($element)) {
if (is_array($value))
self::createNode($value, $node);

} else {
$child = $this-createElement($element, (is_array($value) ? 
null : $value));
$node-appendChild($child);

if (is_array($value))
self::createNode($value, $child);

}
}
}
/*
* Return the generated XML as a string
*
* @accesspublic
* @returnstring
*
*/
public function __toString()
{
return $this-saveXML();
}

/*
* array2xml::query() - perform an XPath query on the XML representation of 
the array
* @param str $query - query to perform
* @return mixed
*/

public function query($query)
{
return $this-xpath-evaluate($query);
}

}



$array = array('employees'= array('employee' = array(
array(
'name'='bill smith',
'address'=
array('number'=1, 'street'='funny'),
'age'=25),
array(
'name'='tom jones',
'address'=
array('number'=12, 'street'='bunny'),
'age'=88),
array(
'name'='dudley doright',
'address'=
array('number'=88, 'street'='munny'),
'age'=23),
array(
'name'='nellie melba',
'address'=
array('number'=83, 'street'='sunny'),
'age'=83)))
);

try {
$xml = new array2xml('root');
$xml-createNode( $array );
echo $xml;
} catch (Exception $e) {
var_dump($e);
}






 
 How can I fix this so that the XML tree, correctly reflects the array
 tree.
 
 TIA
 J
 
 -
 http://www.phpwomen.org/
 
 


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