SimpleXML在PHP中可以通過以下方法實現屬性操作:
$xml = '<bookstore><book category="fiction">PHP Basics</book></bookstore>';
$books = simplexml_load_string($xml);
$category = $books->book['category'];
echo $category; // 輸出: fiction
$xml = '<bookstore><book category="fiction">PHP Basics</book></bookstore>';
$books = simplexml_load_string($xml);
$books->book['category'] = 'non-fiction';
echo $books->asXML(); // 輸出: <bookstore><book category="non-fiction">PHP Basics</book></bookstore>
$xml = '<bookstore><book category="fiction">PHP Basics</book></bookstore>';
$books = simplexml_load_string($xml);
unset($books->book['category']);
echo $books->asXML(); // 輸出: <bookstore><book>PHP Basics</book></bookstore>