Joomla-开源天空

首页 专栏热点 Joomla! 源代码分析 [翻译] Joomla XML 解析器规范 下


[翻译] Joomla XML 解析器规范 下

E-mail

2.2 使用JSimpleXML
例程1. 访问 CDATA 节点

<?php
$xml = new JSimpleXML();
$xml->loadFile($file);

echo $xml->movie[0]->plot->data(); // "So this language. It's like..."
?>
例程2. 访问子节点
 

<?php
$xml = new JSimpleXML();
$xml->loadFile($file);

/* For each <movie> node, we echo a separate <plot>. */
foreach ($xml->movie->children() as $movie) {
   echo $movie->plot->data(), '<br />';
}

?>
例程 3. 访问节点属性

<?php
$xml = new JSimpleXML();
$xml->loadFile($file);

/* Access the <rating> nodes of the first movie.
 * Output the rating scale, too. */
foreach ($xml->movie[0]->rating->children() as $rating) {
   switch((string) $rating->attributes('type')) { // Get attributes as element indices
   case 'thumbs':
       echo $rating, ' thumbs up';
       break;
   case 'stars':
       echo $rating, ' stars';
       break;
   }
}
?>
4. Special Considerations


4.3 字符集

请注意字符集,解析器默认是UTF-8的字符集,目前没有方式来改变字符集,除非你修改源码。


 

相关文章
[翻译] Joomla XML 解析器规范 上
 

发表您的文章评论

您的姓名 (昵称)
标题:
评分: 很差一般较好很好
评论:
验证码:
请输入验证码

» » 登录 »   -   -