Welcome Guest, Not a member yet? Register   Sign In
MY_Xml_Writer - Easy XML writer library
#11

[eluser]JoostV[/eluser]
That's not too hard. Just fetch some data and loop through it.

Code:
/*Fetch students from database*/
$this->load->model('students');
$students = $this->students->get();

/*Initiate XML library*/
$this->load->library('MY_Xml_writer');
$xml = new MY_Xml_writer();
$xml->setRootName('student_data');
$xml->initiate();

/*Construct XML*/
foreach ($students as $student) {
    $xml->startBranch('student', array('year' => $student->year));
    $xml->addNode('f_name', $student->f_name);
    $xml->addNode('l_name', $student->l_name);
    $xml->endBranch();
}

/*Print the XML to screen*/
$xml->getXml(true);


As to your second question: just supply the URL that produces this XML to Flash, via Flashvar.

Say the XML is produced by www.example.com/xml/students. Then you would put a Flashvar in your page, like so.
Code:
<script type='text/javascript' src='jscripts/swfobject.js'></script>
<script type='text/javascript'>
var s1 = new SWFObject('flashfile.swf','myflashname','400','300','9');
s1.addParam('flashvars','xml=xml/students');
s1.write('flashdiv');
</script>

Pick up the FlashVar in Flash and load the XML.
#12

[eluser]Shimura[/eluser]
Thank you JoostV, for you helping.

But i have i little problem : The script return me an error (not with my AMP in local, that's right but online, i have this : Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /.../system/application/libraries/MY_Xml_writer.php on line 40.
#13

[eluser]JoostV[/eluser]
@Shimura: Did you check you have PHP 4.3.0 or higher? The parent class XML was not introduced until then. http://nl2.php.net/xmlwriter

EDIT: Also, XML writer needs to be enabled in your php.ini. This comes as default in many PHP installation, but you never know.
#14

[eluser]Shimura[/eluser]
Hello JoostV,

I need to count the number of node in a foreach :

For example, i have :

<Projet_Graph>1</Projet_Graph>
<Projet_Graph>1</Projet_Graph>
<Projet_Graph>1</Projet_Graph>

And i need this :

<Projet_Graph>3</Projet_Graph>


PHP :

foreach ($value as $value2) {

$xml->addNode('Projet_Graph',count($total));

}

Thank you.
#15

[eluser]JoostV[/eluser]
Add a counter and display its value.
Code:
$iCounter = 0;
foreach ($value as $value2) {
    $xml->addNode('Projet_Graph', $iCounter);
    $iCounter++;
}

Hope it helps you out.
#16

[eluser]Shimura[/eluser]
It's already display one node for one result. I haven't a total result for one node.

I have a foreach with a value $corr = array ( Graphist, AD, Art Director,...); and in my foreach i make a if with preg_match :

Code :

$icounter = 0;

foreach ($correspondance_graph as $corr){

/* Test Projets Graphique */
if(preg_match('`'.$corr.'`', '`'.$row->fonction.'`' )){

$xml->addNode('Projet_Graph',count($icounter));

$icounter++;

}
}

$row->fonction this the result of my query.

The result is always :

<Projet_Graph>1</Projet_Graph>
<Projet_Graph>1</Projet_Graph>
<Projet_Graph>1</Projet_Graph>
#17

[eluser]Shimura[/eluser]
And it's the same with $xml->addNode(‘Projet_Graph’,$icounter);

I think that my foreach make always a node when i have a result of my test preg_match with a word.
#18

[eluser]JoostV[/eluser]
Dear Shimura,

Could you be more specific? I have no idea what you are trying to accomplish.
#19

[eluser]Shimura[/eluser]
I have a table MySQL with function in a Web Project : for example : Art Director, Developer,... And in my XML i try to recover the name of the job like a value (+1) when the prag_match find the same word in my table of correspondence ($correspondance_graph = array(AD, Graphist,...) with my query ($row->fonction, query(SELECT fonction FROM ...) i recover a value in my XML like that :

1</Projet_Graph> -> one match word and for two match word : 2</Projet_Graph>
and not this result :

1</Projet_Graph>
1</Projet_Graph>

This the problem.
#20

[eluser]Shimura[/eluser]
I think that the problem is with the foreach or the condition when he finds a word with a correspondence, he makes a node and not a total of value.




Theme © iAndrew 2016 - Forum software by © MyBB