hey,
i'm in the process of writing a wrapper to handle the xml function for my project. the function does everything i need it to, except for one thing that i cant seem to figure out without creating another object, which i dont want to do if i dont have to!
here is da code:
((within class))
...
public function ern_xml_get_atts( $file = null, $path = null, $conditions = null, $attributes = null, $returncontent = false )
{
//array to build and return to caller
$return = array();
//string to build the query from
$string = '';
//see if the file or path atts are null
if ( $file == null || $path == null )
{
return false;
}
//add xml path to the string
$string = $path;
//add conditions if specified
if ( $conditions != null )
{
$string .= '[@'.$conditions.']';
}
//lets see here
echo $string;
//see if the xml file we want to query has been loaded
if ( isset($this->xml_files_xpath[$file]) )
{
$nodeList = $this->xml_files_xpath[$file]->query($string);
//see for attributes to get
if (strlen($attributes) != 0)
{
//yeah, so explode into an array
$attributes = explode(',',$attributes);
}
$i = 0;
while ( $node = $nodeList->item($i) )
{
//***********
//**here is the issue
if ($returncontent == true)
{
$return[$i]['content'] = $node->content;
}
//***********
//**here is the issue
for ($x=0;$x<=count($attributes)-1;$x++)
{
$tmp = $node->getAttribute($attributes[$x]);
$return[$i][$attributes[$x]] = $tmp;
echo '['.$tmp.']';
}
echo count($attributes);
$i++;
echo "<br><br><br>";
}
//no results whatsoever
if ($i == 0)
{
return false;
}
}
return $return;
}
(())
...
$ret = $xml->ern_xml_get_atts($file,'/users/user', 'uname="user2"', 'password,email', true);
say this is some xml that we're working with:
<users>
<user uname="user1" password="password1" email="1@mail.com" />
<user uname="user2" password="password2" email="2@mail.com">test content</user>
<user uname="user3" password="password3" email="3@mail.com" />
</users>
this function returns an array with the specified attribrutes happily. the thing i'm having trouble with is returning content!
currently the function returns the array:
Array
(
[0] => Array
(
[content] =>
[password] => password2
[email ] => [email ]2@mail.com
)
)
or something there abouts! =]
now i kno that $node->content won't return anythign at all... but thats just so you konw what i wanna do! i managed to get the functionality that i want by creating new dom objects and stuff, but is there a way to get the user2 content between the tags just from the node list??
sorry if i've explained it bad!
thanks a bunch!