Visualizzazione dei risultati da 1 a 6 su 6

Discussione: allineamento tag

  1. #1
    Utente di HTML.it
    Registrato dal
    Jan 2004
    Messaggi
    229

    allineamento tag xml

    ciao a tutti ho un piccolo problema con un semplice script che crea un file xml. In pratica l'allineamento dei tag è continuo. Vi faccio un esempi per capirci meglio. Questo è un solito file prova.xml

    <prova>
    <item p=1>
    <title>Titolo 1<\title>
    <\item>


    <item p=2>
    <title>Titolo 2 <\title>
    <\item>

    <\prova>

    il mio script, riportato sotto, lo crea così:

    <prova><item p=1><title>Titolo <\title><\item><item p=2><title>Titolo <\title><\item><\prova>

    Script in php:

    Class item extends domDocument{

    function __construct(){
    parent::__construct();
    }

    function add_item($idref, $nome, $tipo,$creato_il, $modificatoIl){
    $nomeElement = $this->createElement("nome");
    $nomeElement->appendChild($this->createTextNode($nome));
    $tipoElement = $this->createElement("tipo");
    $tipoElement->appendChild($this->createTextNode($tipo));
    $modElement = $this->createElement("modificatoIl");
    $modElement->appendChild($this->createTextNode($modificatoIl));
    $creElement = $this->createElement("creatoIl");
    $creElement->appendChild($this->createTextNode($creatoIl));
    $rootElement= $this->createElement('item');
    $att=$rootElement->setAttribute('idref', $idref);
    $rootElement->appendChild($nomeElement);
    $rootElement->appendChild($tipoElement);
    $rootElement->appendChild($creElement);
    $rootElement->appendChild($modElement);
    $this->documentElement->appendChild($rootElement);
    }
    }

    <?php

    $dom= new item();
    $dom->load('elenco.xml');
    $i = 1;
    while ($i <= $offset) {
    $dom->add_item($i, $p_nome, $p_tipo, $creatoIl, $modificatoIl);
    $i++;
    }

    $res=$dom-> saveXML();

    ?>

    e dove elenco.xml è

    <ds:elenco xsi:schemaLocation="http://vitali.web.cs.unibo.it/view/TechWeb07/WorkinGroupACDS elenco.xsd" xmlns:ds="http://vitali.web.cs.unibo.it/view/TechWeb07/WorkinGroupACDS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <param>
    <tipo>PdI</tipo>

    </param>


    </ds:elenco>

    come posso creare il mio file xml con il giusto allineamento ???
    Grazie
    Ad Maiora

  2. #2
    Utente di HTML.it
    Registrato dal
    Jan 2004
    Messaggi
    229
    qualcuno può aiutarmi???

    Ad Maiora

  3. #3
    Non so se ho capito bene, ma penso che basterebbe usare \n o \r per una nuova linea e \t per l'indentazione....

  4. #4

    non facile

    lo spero per te
    http://www.totalstationshop.com/
    the portal of topographic instruments

  5. #5
    Per far andare a capo il testo usa \n
    Per fare un'indentazione usa \t

  6. #6
    Utente di HTML.it
    Registrato dal
    Jan 2004
    Messaggi
    229
    ho provato a modificare la funzione add_item da

    function add_item($idref, $nome, $tipo,$creato_il, $modificatoIl){
    $nomeElement = $this->createElement("nome");
    $nomeElement->appendChild($this->createTextNode($nome));
    $tipoElement = $this->createElement("tipo");
    $tipoElement->appendChild($this->createTextNode($tipo));
    $modElement = $this->createElement("modificatoIl");
    $modElement->appendChild($this->createTextNode($modificatoIl));
    $creElement = $this->createElement("creatoIl");
    $creElement->appendChild($this->createTextNode($creatoIl));
    $rootElement= $this->createElement('item');
    $att=$rootElement->setAttribute('idref', $idref);
    $rootElement->appendChild($nomeElement);
    $rootElement->appendChild($tipoElement);
    $rootElement->appendChild($creElement);
    $rootElement->appendChild($modElement);
    $this->documentElement->appendChild($rootElement);
    }

    a

    function add_item($idref, $nome, $tipo,$creato_il, $modificatoIl){
    $nomeElement = $this->createElement("nome");
    $nomeElement->appendChild($this->createTextNode($nome."\n\t"));
    $tipoElement = $this->createElement("tipo");
    $tipoElement->appendChild($this->createTextNode($tipo."\n\t"));
    $modElement = $this->createElement("modificatoIl");
    $modElement->appendChild($this->createTextNode($modificatoIl."\n\t"));
    $creElement = $this->createElement("creatoIl");
    $creElement->appendChild($this->createTextNode($creatoIl."\n\t"));
    $rootElement= $this->createElement('item');
    $att=$rootElement->setAttribute('idref', $idref);
    $rootElement->appendChild($nomeElement);
    $rootElement->appendChild($tipoElement);
    $rootElement->appendChild($creElement);
    $rootElement->appendChild($modElement);
    $this->documentElement->appendChild($rootElement);

    }
    }


    e ora l'indentazione è ancora più sballata. Nessuno sa come posso rimediare a questo dilemma


    <item idref="1"><nome>
    </nome><tipo>pdi
    </tipo><creatoIl>
    </creatoIl><modificatoIl>2007-05-29T18:00:47.0Z
    </modificatoIl></item><item idref="2"><nome>
    </nome><tipo>pdi
    </tipo><creatoIl>
    </creatoIl><modificatoIl>2007-05-29T18:00:47.0Z
    </modificatoIl></item>





    ciao
    Ad Maiora

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.