proxy代理   soft软件   IT 业界特快   norton 诺顿病毒库   代理列表   search FTP搜索   whois IP地理位置   blog 追求完美  
money理财   life生活   RSS聚合门户   firefox WEB浏览器   免费域名   typeset 假古文   AntiVirus 反病毒   ipcn 站点导航  

« 手工初始化 cvsnt | Main | blog 系统 MT - Movable Type »

November 24, 2004

用 XML::Simple 处理 XML

版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本声明。
http://windtear.net/archives/2004/11/24/000256.html

XML::Simple 提供两个功能
XMLin()
XMLout()

或者说它的重大贡献在于屏蔽了技术细节
通过两个接口把XML的处理封装好了
我们可以直接用具体的变量

直接用就行了
http://search.cpan.org/author/GRANTM/XML-Simple-2.13/lib/XML/Simple.pm

XML::Simple
Easy API to maintain XML (esp config files)
XML-Simple-2.13 - 17 Nov 2004 - Grant McLean


use XML::Simple;
my $ref = XMLin([<xml file or string>] [, <options>]);
print $ref->{'config'}->{'1.2.3.4'}->{'os'};
my $xml = XMLout($hashref [, <options>]);
读写的时候 KeyAttr => 'ip', 等一些参数可以影响数据结构
RootName =>'config', 这个写的时候用的到 而且 KeyAttr 也要指定

Data::Dumper 可以用来直接打印 很好看的
use Data::Dumper;
print Dumper($config);
至于 XML 能干啥 为啥 怎么啥
这里就不写了 年初写过一些跨平台
基础知识略


 

本blog WWW

Posted by windtear at November 24, 2004 11:24 PM

Trackback Pings

TrackBack URL for this entry:
http://cgi.windtear.net/cgi-bin/wt-tb.cgi/256

Comments

赞~
XML::Simple的确方便。好的不能再好了。
不知道php下边有没有这样的好模块?

Posted by: xjb at January 12, 2005 11:53 AM

php有simplexml_load_string,simplexml_load_file,暂时没找到XMLout累死函数

Posted by: xjb at January 12, 2005 4:45 PM

实在不行xjb大牛就自己写好了
呵呵

我没用php和xml跑过 一般都用数据库了
看了这一块还要加强学习

Posted by: windtear at January 13, 2005 10:04 AM

Post a comment

Remember Me?


本站使用中的任何问题,请与 windtear SPAM windtear SPAM net 联系
Copyright© 1999-2008 Windtear. All rights reserved.
京ICP备05050670号