Log in

View Full Version : xml to variable


MyPornLife.info
11-19-2009, 04:06 AM
hey.
the xml file name is: list.xml which is on http://domain/path/list.xml

its code is:
<note>
<to>
Tove
</to>
<from>
Jani
</from>
<heading>
Reminder
</heading>
<body>
Don't forget me this weekend!
</body>
</note>

now how can i get variable from that xml file?

so it will be like this: value of $heading will be 'Reminder'

any tutorial for me? plz help me

kh99
11-19-2009, 01:18 PM
Well, if you want to do it in PHP, you could look at this: http://www.w3schools.com/php/php_xml_parser_expat.asp

If you want to do it in vB, you could use the class in includes/class_xml.php, and look at one of the files that uses it for an example, such as includes/adminfunctions_help.php.

That class parses xml in to an array. I made this test file which I put in my forum directory (and I put your xml in a file called "test.xml" in the same directory):

<html><head></head><body>
<?php

$url = "http://localhost/forums/test.xml";

require_once('./includes/class_xml.php');

$xmlobj = new vB_XML_Parser(false, $url);
if ($xmlobj->error_no == 1)
{
echo("error, no url specified");
}
else if ($xmlobj->error_no == 2)
{
echo("error loading xml from '" . $url . "'");
}
else
{
$data = $xmlobj->parse();
$heading = $data['heading'];

echo('$heading = \'' . $heading . "'");
}

?>

</body></html>


The output is:
$heading = ' Reminder '


Hope this helps.

MyPornLife.info
11-19-2009, 01:56 PM
thank you very much :)
just what i was looking for..