perl 操作xml实例
来源:互联网 发布:淘宝举报卖家店铺 编辑:程序博客网 时间:2024/05/22 15:19
1. 用XML::Simple来写xml代码如下:
#!perl -wuse strict; use warnings; use XML::Simple;my $str = <<XML_STRING_;<config logdir="/var/log/foo/" debugfile="/tmp/foo.debug"> <server name="sahara" osname="solaris" osversion="2.6"> <address>10.0.0.101 </address> <address>10.0.1.101 </address> </server> <server name="gobi" osname="irix" osversion="6.5"> <address>10.0.0.102 </address> </server> </config> XML_STRING_ my $xml_ref=XMLin($str,ForceArray => 1 ,KeepRoot => 1); use Data::Dumper;print(Dumper($xml_ref));my $xml_str=XMLout($xml_ref,rootname => 'enter_rootname_here');print("$xml_str\n");
打印效果如下:
2. perl heredoc 在windows上的故障解决
Why do I get an error using Perl's here-doc syntax (<<), that says "Can't find string terminator anywhere before EOF"?
This is a weird error that occurs when your string terminator is on the last line of your script. With a script like:
print <<"END"; The snake is old, and his skin is cold. END
perl is looking for the word END on a line by itself, followed by a line-feed character (\n). If the END is the last line of your script, you have to remember to hit <Enter> after the word END, so that Perl can recognize it as the string terminator.
Most UNIX text editors will do this automatically. Most Windows text editors won't. Thus the problem.
Note that this can also cause a problem with Perl formats, since these are terminated with a single . on a line by itself. However, it's much more rare, since programmers often specify the format for output at the top rather than at the bottom of a file.
3. 通过simplexml 模板,输出xml时的 <;> 有错误,后面采用直接输出txt文件,内容为 “<root>...</root>”的形式,感觉比较简单
- perl 操作xml实例
- Perl 操作xml
- XML操作实例
- XML操作完整实例
- JS操作XML实例
- JDOM操作XML实例
- java xml操作实例
- 在Perl中使用xml-rpc的实例
- 在Perl中使用xml-rpc的实例
- 在Perl中使用xml-rpc的实例
- 在Perl中使用xml-rpc的实例
- 在Perl中使用xml-rpc的实例
- 在Perl中使用xml-rpc的实例
- VC操作XML编程实例
- VC操作XML编程实例
- Sql Server XML 操作实例
- MFC 操作XML 实例 (转)
- VC操作XML编程实例
- 考研数学145分之路:暑期精读大学数学课本
- FSAA (FullSceneAnti-aliasing)全屏抗锯齿技术
- 关于ashx文件的点点滴滴
- C# 同时保持两个窗体激活
- 给央视挑错
- perl 操作xml实例
- android 使用MideaPlayer API来播放简单的应用
- ubuntu下软件包管理
- 100个程序员学习的网站
- 强类型与弱类型
- 银行系统功能说明
- PHP测试题目
- TreeView控件AfterSelect、NodeMouseClick事件的问题
- PHP考试题 测试题 练习题 选择题