How can CSS be utilized to present XML data in a structured and visually appealing manner in PHP?

To present XML data in a structured and visually appealing manner in PHP, CSS can be utilized to style the XML elements. By applying CSS styles to the XML elements, such as setting font styles, colors, margins, and padding, the data can be presented in a visually appealing way. This can help improve the readability and user experience of the XML data when displayed on a webpage.

<?php
$xmlData = '<data><item><name>Item 1</name><price>$10</price></item><item><name>Item 2</name><price>$20</price></item></data>';

// Load the XML data
$xml = simplexml_load_string($xmlData);

// Output the XML data with CSS styles
echo '<style>
        .item {
            border: 1px solid #ccc;
            padding: 10px;
            margin-bottom: 10px;
        }
        .name {
            font-weight: bold;
        }
        .price {
            color: green;
        }
      </style>';

foreach ($xml->item as $item) {
    echo '<div class="item">';
    echo '<div class="name">' . $item->name . '</div>';
    echo '<div class="price">' . $item->price . '</div>';
    echo '</div>';
}
?>