• User Attivo

    XML: problemi con variabili numeriche

    Ciao
    ho realizzato un breve script per ricavare una variabile numerica (numero di secondi) da un file xml

    la struttura dell'xml è di questo tipo
    [PHP]
    <?xml version="1.0" encoding="utf-8"?>
    <ut_response status="ok"><video_details><author>GoldeNProductions</author><title>Urban Ninja</title><rating_avg>4.73</rating_avg><rating_count>94</rating_count><tags>ninja action stunts</tags><description>Urban Ninja</description><update_time>1176319292</update_time><view_count>32442</view_count><comment_count>57</comment_count><upload_time>1173296387</upload_time><length_seconds>314</length_seconds><recording_date /><recording_location /><recording_country /><comment_list></comment_list><channel_list><channel>People & Blogs</channel></channel_list><thumbnail_url><a href="

    " target="_blank">http://sjc-static14.sjc.youtube.com...Y7xLb98gs/2.jpg</a></thumbnail_url><embed_status>ok</embed_status></video_details></ut_response>
    [/PHP]

    Lo script è questo

    [PHP]
    filexml = //url dell'xml
    mioxml = new XML();
    mioxml.ignoreWhite = true;
    myarray = new Array();
    mioxml.load(filexml);
    mioxml.onLoad = ElaboraXML;

    function ElaboraXML (success) {
    if (mioxml.loaded) {
    myarray = mioxml.firstChild.firstChild.childNodes;

    for (i=0;i<=myarray.length;i++){
    if (myarray*.nodeName== "length_seconds"){
    tot_sec = myarray*.firstChild;
    tot_sec=Number(tot_sec);
    }
    }

    };
    };
    [/PHP]

    la var tot_sec restituisce correttamente il valore "314"
    ma se provo ad eseguire operazioni matematiche con questa variabile mi restituisce "Undefined"
    come faccio a trasformare il valore in una variabile numerica?

    Grazie


  • Super User

    Ciao,
    fai così:

    
    tot_sec = Number(myarray*.firstChild);
    
    

    e togli
    tot_sec=Number(tot_sec);