views:

56

answers:

5

Is it possible to put a function in an XML field?

For example i have the following xml file:

<?xml version="1.0" encoding="utf-8" ?> 
<prova>
<prova>
<continente>Europa</continente> 
<stato>Italia</stato> 
<societa>SSC Napoli</societa> 
<actual>1.09769</actual> 
<estimate>0.447969</estimate> 
</prova>
<prova>
....
</prova>
</prova>

Is it possible to insert a function into 'actual' and 'estimate' fields which change randomly by a timer the values? Thanks in advance.

A: 

No.

XML is a simple data format which does support functions.
Unlike HTML, you can't put in a Javascript block inside an XML file to manipulate the data.

SLaks
+1  A: 

You would want any function to be part of what generated the xml, not the xml itself. In otherwords, you would have some script update and actually generate the xml with updated values.

George Sisco
yeah that's the point
Franky
+1  A: 

However you generate the XML is the place to put this function. If you generate the XML via PHP you would do a <?php echo blah ?> in the middle. However, if it's static XML that you hand built, then no, there is no way to put a function in.

Chuck Vose
yeah it's generated by a php request from a client by httpservice e4x format
Franky
+1  A: 

Please, try something like this:

<?php
$doc = new DOMDocument();
$doc->load('provas.xml');

$provas = $doc->getElementsByTagName("prova");
foreach( $provas as $prova )
{
    $actual = $prova->getElementsByTagName("actual");
    $estimate = $prova->getElementsByTagName("estimate");

    $random = $doc->createElement("random", "your data");
    $actual->appendChild( $random );
    $estimate->appendChild( $random );
}
?>
Rubens Farias
the php is automatically generated by Flex Builder and it's composed by 397 code lines so i really don't know how it's possible to manage it. Howhewer thanks
Franky
@Franky, you'll need to take XML returned by your webservice and to edit it; this keywords can help to search: `"xml, php, dom, xpath, appendchild"`
Rubens Farias
thank you Rubens
Franky
A: 

Agree with Chuck above. Either generate the XML with the desired values, in which case the "function" would be part of the generation, or use XSL to transform to HTML, but you cannot ultimately embed "content that changes" inside the XML, you can only "give" the XML the value after generation.

funkymushroom