Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Lösung

Verwenden Sie die Funktionen simplexml_import_dom() und dom_import_simplexml(), um XML-Knoten zwischen den beiden Erweiterungen auszutauschen.

$xmlJla = <<<EOD
<team name="JLA"><held name="Clark Kent">Superman</held><held name="Bruce Wayne">Batman</
held></team>
EOD;

$xmlAvengers = <<<EOD
<team name="Avengers"><held name="Steve Rogers">Captain America</held><held name="Tony
Stark">Iron Man</held></team>
EOD;

$simpleXmlJla = simplexml_load_string($xmlJla);
$simpleXmlAvengers = simplexml_load_string($xmlAvengers);

$dom   = new DOMDocument();
$dom->formatOutput = true;
$team = $dom->appendChild($dom->createElement('team'));
$team->setAttribute('name', 'Amalgam');

$superman = dom_import_simplexml($simpleXmlJla->held[0]);
$superman = $dom->importNode($superman, true);
$team->appendChild($superman);

$ironman  = dom_import_simplexml($simpleXmlAvengers->held[1]);
$ironman  = $dom->i....

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint