AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

[PHP] XML und PHP

Ein Thema von Meflin · begonnen am 4. Sep 2004 · letzter Beitrag vom 5. Sep 2004
 
Benutzerbild von fiasko
fiasko

Registriert seit: 10. Dez 2002
Ort: Dresden
506 Beiträge
 
#16

Re: [PHP] XML und PHP

  Alt 5. Sep 2004, 11:31
Hallo,

ich hab mir das mal angeschaut, hier ein kleines Beispiel was dir vielleicht hilft:

Code:
<?php                                                                                                                        
                                                                                                                               
header('Content-Type: text/plain');                                                                                          
                                                                                                                               
$xpath = "//text[@id='3']";                                                                                                  
                                                                                                                               
/* Datei einlesen */                                                                                                           
$doc  = xmldocfile('test.xml');                                                                                              
                                                                                                                               
                                                                                                                               
echo "XPath \"$xpath\":\n\n";                                                                                                
                                                                                                                               
/* Neuen Context erstellen fuer XPath */                                                                                       
$con  = $doc->xpath_new_context();                                                                                          
                                                                                                                               
/* XPath auswerten ($nodes ist Klasse XPathObject) */                                                                         
$nodes = $con->xpath_eval_expression($xpath);                                                                                
                                                                                                                               
/* Die Ergebnismenge ausgeben... */                                                                                           
foreach($nodes->nodeset as $node) {                                                                                           
    echo "\t",$node->tagname,":\n";                                                                                          
                                                                                                                               
    /* Die Kind-Knoten nach dem Text-Node durchsuchen... */                                                                   
    foreach(domxml_children($node) as $child) {                                                                               
        if ($child->type == XML_TEXT_NODE) {                                                                                   
            echo "\t\t",$child->content,"\n";                                                                                
        }                                                                                                                     
    }                                                                                                                         
}                                                                                                                             
                                                                                                                               

/* Zum Schluss noch entwas hinzufuegen... */
$root = $doc->root();                                                                                  
$node = $root->new_child('mytest');                                                                                          
$node->set_attribute('ip',$REMOTE_ADDR);                                                                                      
                                                                                                                               
echo "\n\n************************************\n\n";                                                                          
echo $doc->dumpmem();
XML-Code:
<root>
    <text id="1">eins</text>
    <text id="2">zwei</text>
    <text id="3">drei</text>
</root>
Als ergebnis kommt dann sowas raus:

Code:
XPath "//text[@id='3']":

   text:
      drei


************************************

<?xml version="1.0"?>
<root>
    <text id="1">eins</text>
    <text id="2">zwei</text>
    <text id="3">drei</text>
<mytest ip="10.0.0.21"/></root>
Das ganze ist aber mit PHP 4.1.2 (!) getestet...


[edit]
Nur ein Typo im PHP-Code gefixt...
[/edit]
Thomas Liske
Posts comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

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

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 06:30 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz