Skip to content

Instantly share code, notes, and snippets.

@pchatterjee
Created February 24, 2020 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pchatterjee/6735b844beca6aebf8a479a051edcc53 to your computer and use it in GitHub Desktop.
Save pchatterjee/6735b844beca6aebf8a479a051edcc53 to your computer and use it in GitHub Desktop.
<?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