Zurück   Flashforum > Flash und Server > PHP und MySQL

Antwort
 
LinkBack Themen-Optionen Ansicht
Alt 14-07-2010, 20:55   #1 (permalink)
Neuer User
 
Registriert seit: Apr 2006
Beiträge: 855
XML in mit PHP ausgeben

wie kann xml einträge in php ausgeben


dass ist mein xml
PHP-Code:
<?xml version="1.0" encoding="ISO-8859-1"?>

<note>

    <note1>
        <my_child1>TOM</my_child1>
        <my_child2>Jerry</my_child2>
        <my_child3>Reminder</my_child3>
        <my_child4><![CDATA[Tom & Jerry]]></my_child4>
    </note1>

    <note1>
        <my_child1>TOM</my_child1>
        <my_child2>Jerry</my_child2>
        <my_child3>Reminder</my_child3>
        <my_child4><![CDATA[Tom & Jerry]]></my_child4>
    </note1>

    <note1>
        <my_child1>TOM</my_child1>
        <my_child2>Jerry</my_child2>
        <my_child3>Reminder</my_child3>
        <my_child4><![CDATA[Tom & Jerry]]></my_child4>
    </note1>

</note>
und dies ist mein php
PHP-Code:
<?php
$xml 
simplexml_load_file("eintrag.xml");

foreach (
$xml->children() as $child){

     foreach (
$child->children() as $third_gen) {
     
          echo 
"Child node: " $third_gen "<br />";
    }
  }
?>
es wird schon alle einträge ausgegeben

wie kann ich aber nun die jeweilige attribute in array packen um später bearbeiten zu können


danke vorraus
palpalo ist offline   Mit Zitat antworten
Alt 15-07-2010, 02:15   #2 (permalink)
Neuer User
 
Registriert seit: Apr 2006
Beiträge: 855
habs so geschaft die xml inhalte zu laden

PHP-Code:
<?php

$xml 
"news.xml";

$xml simplexml_load_file($xml);

   foreach(
$xml as $my_items){
       
$child_count++;
      
    
$myA1$my_items->my_child1
    
$myA2$my_items->my_child2;
        
$myA3$my_items->my_child3;

    echo 
"<input name=\"myA1_$i\" type=\"text\" value=\"$myA1\" /><br />\n<br />\n"
    echo 
"<input name=\"myA2_$i\" type=\"text\" value=\"$myA2\" /><br />\n<br />\n"
    echo 
"<input name=\"myA3_$i\" type=\"text\" value=\"$myA3\" /><br />\n<br />\n"
}
?>
wie kann ich nun schön als tabelle erstmal ausgeben
palpalo ist offline   Mit Zitat antworten
Alt 15-07-2010, 07:05   #3 (permalink)
Neuer User
 
Registriert seit: Sep 2009
Beiträge: 216
Hey,
hier hast du mal eine Funktion, die dir die ganze XML in ein Array packt + Attribute etc.

PHP-Code:
function &_xml2array($contents$get_attributes false) {
    if ( !
function_exists('xml_parser_create') ) {
        
show_error('Server does not support xml_parser_create');
    }
    if ( !isset(
$contents) ) {
        
show_error('Missing arguments for _xml2array');
    }

    
$parser xml_parser_create('ISO-8859-1');
    
xml_parser_set_option$parserXML_OPTION_TARGET_ENCODING'UTF-8' );
    
xml_parser_set_option$parserXML_OPTION_SKIP_WHITE);
    
xml_parse_into_struct$parser$contents$xml_values );
    
xml_parser_free$parser );

    unset(
$parser);
    unset(
$contents);
    
    
$ret = array();

    
// Empty XML tree...?
    
if(!$xml_values) return $ret;

    
$parents = array();
    
$current =& $ret;
    
    foreach (
$xml_values as $data) {
        unset(
$value$attributes);
        
extract($data);
        unset(
$data);
        if ( !isset(
$value) ) $value null;

        if ( 
$get_attributes ) {
            if ( isset(
$attributes) ) {
                
$value = array(
                    
'value' => $value
                    
'attr' => array()
                );
                
$value['attr'] = $attributes;
            }
        }
        if (
$type == "open") {
            
$parents[$level-1] =& $current;
            if ( !
is_array($current) || !in_array($tagarray_keys($current)) ) {
                if ( isset(
$value['attr']) ) {
                    
$current[$tag] = array(
                        
'attr' => $value['attr']
                    );
                } else {
                    
$current[$tag] = array();
                }
                
$current =& $current[$tag];
            } else {
                if ( isset(
$current[$tag][0]) ) {
                    
array_push($current[$tag], $value);
                } else {
                    
$current[$tag] = array($current[$tag], $value);
                }
                
$last count($current[$tag]) - 1;
                
$current =& $current[$tag][$last];
            }
        } elseif (
$type == "complete") {
            if ( !isset(
$current[$tag]) ) {
                
$current[$tag] = $value;
            } else {
                if ( 
is_array($current[$tag]) && $get_attributes == || isset($current[$tag][0]) && is_array($current[$tag][0]) && $get_attributes == ) {
                    
array_push($current[$tag], $value);
                } else {
                    
$current[$tag] = array($current[$tag], $value);
                }
            }
        } elseif (
$type == 'close') {
            
$current =&  $parents[$level-1];
        }
    }
    return 
$ret;

Kanns es dir ja mal ausgeben lassen mit var_dump(); also das erstellte Array. Damit kann man ganz gut arbeiten.

Und dann müsstest du nur 2 Schleifen bauen.
1. Schleife: Für Note das wird dann dein tr Tag
2. Schleife: Für die Childs die in deinen td Tag dann rein kommen

Mit freundlichen Grüßen

Cas
CaselPasel ist offline   Mit Zitat antworten
Antwort

Lesezeichen

Themen-Optionen
Ansicht

Forumregeln
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks sind an
Pingbacks sind an
Refbacks sind an


Ähnliche Themen
Thema Autor Forum Antworten Letzter Beitrag
Videogröße ausgeben Michaela1986 Flash Einsteiger 1 13-08-2007 14:11
Text ein- und ausgeben tahlo Flash Einsteiger 21 12-03-2006 10:31
url ausgeben?? RoyalTS Flash MX 2 07-05-2003 13:56
Tabelle ausgeben kressevadder ActionScript 1 4 03-03-2003 14:26
html ausgeben fmatte Flash MX 1 19-01-2003 13:42


Alle Zeitangaben in WEZ +1. Es ist jetzt 14:33 Uhr.

Domains, Webhosting & Vserver von Host Europe
Unterstützt das Flashforum!
Adobe User Group


Copyright ©1999 – 2012 Marc Thiele