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>