Visualizzazione dei risultati da 1 a 5 su 5
  1. #1

    SimpleXML load php file con Content-type: text/xml

    Ciao.
    file xml.php (pensate che lo potevo fare
    in modo dinamico con un result mysql )

    Codice PHP:
    <?php
    $xmlstr 
    "<?xml version=\"1.0\" standalone=\"yes\"?>";
    $xmlstr .= "<movies>\n<movie>Behind the Parser</movie>\n</movies>\n";
    header('Content-type: text/xml; charset=utf-8');
    echo 
    $xmlstr;
    ?>

    file loadXml

    Codice PHP:
    <?php
    if (file_exists('xml.php')) {
       
    $xml simplexml_load_file('xml.php');

       
    var_dump($xml);
    } else {
       exit(
    'Failed to open test.xml.');
    }
    ?>
    E l'errore:

    Warning: xml.php:2: parser error : Start tag expected, '<' not found in f:\wamp\www\xml\example\mioplot.php on line 3

    Warning: $xmlstr = ""; in c:\xxx\www\xml\example\loadXml.php on line 3

    Warning: ^ in c:\xxx\www\xml\example\loadXml.php on line 3
    bool(false)

    Il file xml.php è un valido file xml
    quindi non capisco il perchè dell'errore
    c'è qc che mi spiega l'arcano.
    (Provato sia da locale che su web)



    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  2. #2
    La cosa non cambia facendo una
    cosa del genere con o senza header

    Codice PHP:
    <?php
    $doc 
    = new DOMDocument('1.0');
    // we want a nice output
    $doc->formatOutput true;
    $root $doc->createElement('book');
    $root $doc->appendChild($root);
    $title $doc->createElement('title');
    $title $root->appendChild($title);
    $text $doc->createTextNode('This is the title');
    $text $title->appendChild($text);
    echo 
    $doc->saveXML() . "\n";
    ?>

    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  3. #3

    .............

    Scusate l'uppete ma non mi torna

    Se utilizzo Ajax per recuperare il file xmp.php
    e relativi valori è tutto a posto.

    Perchè con PHP mi dà ERRORE.

    Potrei salvare il file con ad esempio
    $doc->save("newfile.xml") ma PP la
    cosa non mi torna !!!!!!!!


    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  4. #4
    Utente di HTML.it L'avatar di Graboid
    Registrato dal
    Oct 2004
    Messaggi
    619
    Forse il problema e' che a linea 3, anche se come stringa, c'e un <? che potrebbe essere interpretato male.
    Prova a togliere il prologo xml e vedi se funziona, così siamo sicuri che sia quello.
    Potresti sostituire < con la sua entità xml.

    Ciao

  5. #5

    ....

    Ciao.
    Ti ringrazio dell'interessamento ma titta !



    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.