generare xml con php

ciao! sto rendendo dinamico un treemenu che carica i dati dall'xml, sto generando l'xml con php e i dati provengono da joomla virtuemart, le query funzionano la struttura sembra giusta ma mi dice sempre xml incorrect, mi aiutate a rendere corretto questo xml??

questo è il cod che lo genera:

$query = mysql_query("SELECT * FROM jos_vm_category",$connessione);


if ($query==FALSE) die("errore nella composizione della query");


echo "<?xml version='1.0' encoding='iso-8859-1'?>\n";
echo "<tree id='0'>\n";
?>

<item id="dhtmlxTree" text="dhtmlxTree" im0="dhtmlxtree_icon.gif" im1="dhtmlxtree_icon.gif" im2="dhtmlxtree_icon.gif" open="true">
<userdata name="url">../dhtmlxTree/doc</userdata>
<userdata name="thisurl">../dhtmlxTree/doc/guide.html</userdata>
<?php
$j=0;
$parentchilds=array();

 while ($row= mysql_fetch_array($query)){

    $parentchilds[]=$row[0];
    $arrid=$row[0];
 

   echo '<item text=""".$row[0].""" id=""".$row[0].""">\n';
   echo '<userdata name="""url""">guide.html</userdata>\n';

  

    $query2 = mysql_query("SELECT * FROM jos_vm_category_xref WHERE category_parent_id =$arrid",$connessione);

    $num_rows2 = mysql_num_rows($query2);

    if($num_rows2 >0){
        $i=0;
        while ($row2= mysql_fetch_array($query2)){
             $parentchilds[$j]=array();
             $parentchilds[$j][$i]=$row2[1];
           // echo  $row2[1];
             echo '<item text=""".$row2[1].""" id=""".$row2[1]."""/>\n';
             $i++;
        }

    }
       
        echo"</item>\n";
  
     $j++;
 }

    echo "</item>\n";
echo "</tree>\n";

questo è l'output:

<?xml version="1.0" encoding"iso-8859-1"?>
<tree id="0">

<item id="dhtmlxTree" text="dhtmlxTree" im0="dhtmlxtree_icon.gif" im1="dhtmlxtree_icon.gif" im2="dhtmlxtree_icon.gif" open="true">
<userdata name="url">../dhtmlxTree/doc</userdata>
<userdata name="thisurl">../dhtmlxTree/doc/guide.html</userdata>
<item text="1" id="1">
<userdata name="url">guide.html</userdata>
</item>
<item text="2" id="2">
<userdata name="url">guide.html</userdata>
<item text="4" id="4"/>
<item text="5" id="5"/>

</item>
<item text="3" id="3">
<userdata name="url">guide.html</userdata>
</item>
<item text="4" id="4">
<userdata name="url">guide.html</userdata>
<item text="6" id="6"/>
</item>
<item text="5" id="5">
<userdata name="url">guide.html</userdata>
<item text="7" id="7"/>
</item>
<item text="6" id="6">
<userdata name="url">guide.html</userdata>

</item>
<item text="7" id="7">
<userdata name="url">guide.html</userdata>
</item>
</item>
</tree>

e questo è l'xml originale funzionante come dovrebbe essere:

<?xml version="1.0" encoding="iso-8859-1"?>
<tree id="0">
         <item id="dhtmlxTree" text="dhtmlxTree" im0="dhtmlxtree_icon.gif" im1="dhtmlxtree_icon.gif" im2="dhtmlxtree_icon.gif" open="true">
            <userdata name="url">
               ../dhtmlxTree/doc
            </userdata>
            <userdata name="thisurl">
               ../dhtmlxTree/doc/guide.html
            </userdata>
            <item text="Main Features" id="mf">
               <userdata name="url">guide.html</userdata>
            </item>
            <item text="Supported Browsers" id="browsers">
               <userdata name="url">guide.html</userdata>
            </item>
            <item text="Guide" id="guide">
               <userdata name="url">guide.html</userdata>
               <item text="Initialize object on page" id="init"/>
               <item text="Initialization from HTML" id="inithtml"/>
               <item text="Loading data with XML" id="xmlload"/>
               <item text="Adding nodes with Script" id="scriptadd"/>
               <item text="Icons in Tree" id="g_icons"/>
               <item text="Setting custom icons to nodes" id="iconscust"/>
               <item text="Checkboxes in tree" id="checkbox"/>
               <item text="Radiobuttons in tree" id="radiobut"/>
               <item text="Tooltips" id="tooltip"/>
               <item text="Moving nodes" id="move"/>
               <item text="Sorting nodes" id="sort"/>
               <item text="Increasing Performance" id="guide_perf"/>
               <item text="Dynamical Loading" id="dyntree">
                  <userdata name="url">dyn_loading.html</userdata>
               </item>
               <item text="Smart XML Parsing" id="smartxml"/>
               <item text="Distributed Parsing" id="distparse"/>
               <item text="Set Event Handlers" id="handlers"/>
               <item text="Drag-and-drop technics" id="dnd"/>
               <item text="Drag-and-drop between iframes" id="dndifr"/>
               <item text="Manipulating nodes" id="nodesman"/>
               <item text="Refreshing nodes" id="refresh"/>
               <item text="Serialization" id="serialize"/>
               <item text="Search functionlity" id="search"/>
               <item text="Multiline tree items" id="multiline"/>
               <item text="Add Items Counter" id="counter"/>
               <item text="Context Menu" id="context_menu"/>
               <item text="Cold Fusion Tag for dhtmlXTree" id="cftag"/>
               <item text="Error handling in dhtmlXTree" id="error"/>
               <item text="Keyboard Navigation" id="keyboard"/>
               <item text="Editable Items" id="edititem"/>
               <item text="Simultanious Server Update" id="dataprocessor"/>
               <!--item text="*.Net Implementation" id="dotnet"/-->
               
            </item>
            <item text="API Functions" id="api">
               <userdata name="url">alpha.html</userdata>
               <item text="Object constructor" id="api_obj" im0="leaf_new.gif">
                  <userdata name="url">objects.html</userdata>
               </item>
               <item text="Events" id="api_ev" im0="leaf_new.gif">
                  <userdata name="url">events.html</userdata>
               </item>
               <item text="Alphabeticaly sorted" id="api_a">
                  <userdata name="url">alpha.html</userdata>
               </item>
               <item text="Grouped by Type" id="api_t">
                  <userdata name="url">tgroup.html</userdata>
               </item>
               <item text="Grouped by Object" id="api_o">
                  <userdata name="url">ogroup.html</userdata>
               </item>
               <!--item text="*Event handlers arguments" id="events_args">
                  <userdata name="file">events.html</userdata>
               </item-->
            </item>
            <item text="Special Technique" id="spec">
               <userdata name="url">special.html</userdata>
               <item text="Links in tree" id="spec_link"/>
               <item text="Drag-n-drop outside tree" id="spec_dnd_out"/>
               <!--item text="*Context Menu" id="spec_cm"/-->
            </item>
            <item text="Frequently asked questions" id="kb_faq">
               <userdata name="url">faq.html</userdata>
               <item text="Licenses" id="kb_faq_lic"/>
               <item text="Performance. Dynamical Loading" id="kb_faq_perf"/>
               <item text="Drag-n-drop, Nodes ordering" id="kb_faq_dnd"/>
               <item text="API, Initialization" id="kb_faq_api"/>
               <item text="Other Questions" id="kb_faq_else"/>
               <item text="IE images caching troubleshooting" im0="leaf_new.gif" id="tree_im_cach">
                      <userdata name="url">trouble.html</userdata> 
               </item>
            </item>
         </item>
         
         
         
         
         
         

      </tree>

non capisco cosa sbaglio, grazie dell'aiuto

inviato 6 anni fa
surferbloggy
modificato 6 anni fa
X 0 X

nemmeno con questo output cambiando le virgolette mi funziona:

<?xml version='1.0' encoding='iso-8859-1'?>
<tree id='0'>

<item id="dhtmlxTree" text="dhtmlxTree" im0="dhtmlxtree_icon.gif" im1="dhtmlxtree_icon.gif" im2="dhtmlxtree_icon.gif" open="true">
<userdata name="url">../dhtmlxTree/doc</userdata>
<userdata name="thisurl">../dhtmlxTree/doc/guide.html</userdata>
<item text='1' id='1'>
<userdata name='url'>guide.html</userdata>
</item>
<item text='2' id='2'>
<userdata name='url'>guide.html</userdata>
<item text='4' id='4'/>
<item text='5' id='5'/>

</item>
<item text='3' id='3'>
<userdata name='url'>guide.html</userdata>
</item>
<item text='4' id='4'>
<userdata name='url'>guide.html</userdata>
<item text='6' id='6'/>
</item>
<item text='5' id='5'>
<userdata name='url'>guide.html</userdata>
<item text='7' id='7'/>
</item>
<item text='6' id='6'>
<userdata name='url'>guide.html</userdata>

</item>
<item text='7' id='7'>
<userdata name='url'>guide.html</userdata>
</item>
</item>
</tree>
risposto 6 anni fa
surferbloggy
X 0 X

Guarda bene la struttura originale.

Se non sbaglio quando c'è userdata è così:

<item ....>
    <userdata ...> ... </userdata>
</item>
risposto 6 anni fa
Mario Santagiuliana
X 0 X
Grazie, ora ho corretto e l'output è questo mi da ancora incorrect forse è /n per andare a capo che non gli piace, non lo so oppure non me ne accorgo ed è ancora sbagliata la struttura:

<?xml version='1.0' encoding='iso-8859-1'?>
<tree id='0'>

<item id="dhtmlxTree" text="dhtmlxTree" im0="dhtmlxtree_icon.gif" im1="dhtmlxtree_icon.gif" im2="dhtmlxtree_icon.gif" open="true">
<userdata name="url">../dhtmlxTree/doc</userdata>
<userdata name="thisurl">../dhtmlxTree/doc/guide.html</userdata>
<item text='1' id='1'>
<userdata name='url'>guide.html</userdata>
</item>
<item text='2' id='2'>
<userdata name='url'>guide.html</userdata>
<item text='4' id='4'/>
<item text='5' id='5'/>

</item>
<item text='3' id='3'>
<userdata name='url'>guide.html</userdata>
</item>
<item text='4' id='4'>
<userdata name='url'>guide.html</userdata>
<item text='6' id='6'/>
</item>
<item text='5' id='5'>
<userdata name='url'>guide.html</userdata>
<item text='7' id='7'/>
</item>
<item text='6' id='6'>
<userdata name='url'>guide.html</userdata>

</item>
<item text='7' id='7'>
<userdata name='url'>guide.html</userdata>
</item>
</item>
</tree>
risposto 6 anni fa
surferbloggy
X 0 X

Ricontrolla la struttura e fa in modo che corrisponda.

L'errore che ti propone non aggiunge nessuna informazione in più?

risposto 6 anni fa
Mario Santagiuliana
X 0 X
Effettua l'accesso o registrati per rispondere a questa domanda