Created
February 24, 2020 22:20
-
-
Save pchatterjee/6735b844beca6aebf8a479a051edcc53 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$wines = new DOMDocument(); | |
$wines->load( 'wines.xml' ); | |
$categorys = $wines->getElementsByTagName("category"); | |
foreach( $categorys as $category ) { | |
echo "<p>"; | |
$name = $category->getAttribute("name"); | |
echo "<b>Type: $name</b><br/>"; | |
$products = $category->getElementsByTagName("product"); | |
foreach( $products as $product ) { | |
$titles = $product->getElementsByTagName( "title" ); | |
$title = $titles->item(0)->nodeValue; | |
echo "$title<br/>"; | |
} | |
echo "</p>"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment