<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>评论：[Perl]用XML::Simple解析XML文件</title>
	<atom:link href="http://tech.idv2.com/2008/09/03/perl-xml-simple/feed/" rel="self" type="application/rss+xml" />
	<link>http://tech.idv2.com/2008/09/03/perl-xml-simple/</link>
	<description>关注Web开发技术，关注Internet。</description>
	<lastBuildDate>Fri, 03 Sep 2010 10:05:58 +0800</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>来自：zhangxiaoqiang</title>
		<link>http://tech.idv2.com/2008/09/03/perl-xml-simple/comment-page-1/#comment-11430</link>
		<dc:creator>zhangxiaoqiang</dc:creator>
		<pubDate>Fri, 19 Dec 2008 00:54:57 +0000</pubDate>
		<guid isPermaLink="false">http://tech.idv2.com/2008/09/03/perl-xml-simple/#comment-11430</guid>
		<description>好的，我知道了，谢谢啊！</description>
		<content:encoded><![CDATA[<p>好的，我知道了，谢谢啊！</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：charlee</title>
		<link>http://tech.idv2.com/2008/09/03/perl-xml-simple/comment-page-1/#comment-11425</link>
		<dc:creator>charlee</dc:creator>
		<pubDate>Tue, 16 Dec 2008 05:27:45 +0000</pubDate>
		<guid isPermaLink="false">http://tech.idv2.com/2008/09/03/perl-xml-simple/#comment-11425</guid>
		<description>@zhangxiaoqiang 那就直接用XML::Simple解析之后用foreach循环结果，依次取出每个结果就行了啊。取出之后输出也好return也好直接组成SQL执行也好，可以随便使用。

foreach遍历hash: 
foreach my $key (keys %$hash) {
  print $hash-&gt;{$key};
}
foreach遍历array: 
foreach my $value (@$array) {
  print $value;
}

至于应该用哪个，用Data::Dumper把解析结果dump出来看看，{}的部分就用hash，[]部分就是数组。</description>
		<content:encoded><![CDATA[<p>@zhangxiaoqiang 那就直接用XML::Simple解析之后用foreach循环结果，依次取出每个结果就行了啊。取出之后输出也好return也好直接组成SQL执行也好，可以随便使用。</p>
<p>foreach遍历hash:<br />
foreach my $key (keys %$hash) {<br />
  print $hash->{$key};<br />
}<br />
foreach遍历array:<br />
foreach my $value (@$array) {<br />
  print $value;<br />
}</p>
<p>至于应该用哪个，用Data::Dumper把解析结果dump出来看看，{}的部分就用hash，[]部分就是数组。</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：zhangxiaoqiang</title>
		<link>http://tech.idv2.com/2008/09/03/perl-xml-simple/comment-page-1/#comment-11423</link>
		<dc:creator>zhangxiaoqiang</dc:creator>
		<pubDate>Mon, 15 Dec 2008 06:22:30 +0000</pubDate>
		<guid isPermaLink="false">http://tech.idv2.com/2008/09/03/perl-xml-simple/#comment-11423</guid>
		<description>另外还有一个问题请大侠赐教：用xml::sample的出来的那个
$VAR1={......}这个怎么用foreach遍历啊，能否举个例子？</description>
		<content:encoded><![CDATA[<p>另外还有一个问题请大侠赐教：用xml::sample的出来的那个<br />
$VAR1={&#8230;&#8230;}这个怎么用foreach遍历啊，能否举个例子？</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：zhangxiaoqiang</title>
		<link>http://tech.idv2.com/2008/09/03/perl-xml-simple/comment-page-1/#comment-11422</link>
		<dc:creator>zhangxiaoqiang</dc:creator>
		<pubDate>Mon, 15 Dec 2008 06:13:59 +0000</pubDate>
		<guid isPermaLink="false">http://tech.idv2.com/2008/09/03/perl-xml-simple/#comment-11422</guid>
		<description>[colum1]123[/colum1]
[colum2]321[/colum2]
[value colum3=&quot;3&quot;/]

输出的结果我想让他这样123&#124;321&#124;3</description>
		<content:encoded><![CDATA[<p>[colum1]123[/colum1]<br />
[colum2]321[/colum2]<br />
[value colum3="3"/]</p>
<p>输出的结果我想让他这样123|321|3</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：zhangxiaoqiang</title>
		<link>http://tech.idv2.com/2008/09/03/perl-xml-simple/comment-page-1/#comment-11421</link>
		<dc:creator>zhangxiaoqiang</dc:creator>
		<pubDate>Mon, 15 Dec 2008 06:08:44 +0000</pubDate>
		<guid isPermaLink="false">http://tech.idv2.com/2008/09/03/perl-xml-simple/#comment-11421</guid>
		<description>尖括号的内容都屏蔽掉了~~</description>
		<content:encoded><![CDATA[<p>尖括号的内容都屏蔽掉了~~</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：zhangxiaoqiang</title>
		<link>http://tech.idv2.com/2008/09/03/perl-xml-simple/comment-page-1/#comment-11420</link>
		<dc:creator>zhangxiaoqiang</dc:creator>
		<pubDate>Mon, 15 Dec 2008 06:05:22 +0000</pubDate>
		<guid isPermaLink="false">http://tech.idv2.com/2008/09/03/perl-xml-simple/#comment-11420</guid>
		<description>是这样的，我得到一个xml，需要把他解析，然后把解析完的文件再入库！库结构已经有了比如一张表的字段：
colum1
colum2
colum3
这三个字段可能是xml里边的节点也可能是属性
123
123

我需要解析的文件格式：123&#124;123&#124;3
不知道我的需求有没有什么好的办法，谢谢啦！</description>
		<content:encoded><![CDATA[<p>是这样的，我得到一个xml，需要把他解析，然后把解析完的文件再入库！库结构已经有了比如一张表的字段：<br />
colum1<br />
colum2<br />
colum3<br />
这三个字段可能是xml里边的节点也可能是属性<br />
123<br />
123</p>
<p>我需要解析的文件格式：123|123|3<br />
不知道我的需求有没有什么好的办法，谢谢啦！</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：charlee</title>
		<link>http://tech.idv2.com/2008/09/03/perl-xml-simple/comment-page-1/#comment-11419</link>
		<dc:creator>charlee</dc:creator>
		<pubDate>Mon, 15 Dec 2008 03:31:36 +0000</pubDate>
		<guid isPermaLink="false">http://tech.idv2.com/2008/09/03/perl-xml-simple/#comment-11419</guid>
		<description>@zhangxiaoqiang 你说的是不是数据库里面那种表？可以把字段作为属性名称，内容作为属性值；也可以把字段作为节点名称，内容作为节点的文本内容。如：

1) 字段作为属性名称，内容作为属性值
[library]
  [book author=&quot;aaa&quot; year=&quot;2008&quot; title=&quot;Hello&quot;/]
  [book author=&quot;bbb&quot; year=&quot;2007&quot; title=&quot;World&quot;/]
[/library]

2) 字段作为节点名称，内容作为节点的文本内容
[library]
  [book]
    [author]aaa[/author]
    [year]2008[/year]
    [title]Hello[/title]
  [book]
  [book]
    [author]bbb[/author]
    [year]2007[/year]
    [title]World[/title]
  [book]
[/library]

将上面的方括号看作尖括号。不知道是否回答了你的问题？</description>
		<content:encoded><![CDATA[<p>@zhangxiaoqiang 你说的是不是数据库里面那种表？可以把字段作为属性名称，内容作为属性值；也可以把字段作为节点名称，内容作为节点的文本内容。如：</p>
<p>1) 字段作为属性名称，内容作为属性值<br />
[library]<br />
  [book author="aaa" year="2008" title="Hello"/]<br />
  [book author="bbb" year="2007" title="World"/]<br />
[/library]</p>
<p>2) 字段作为节点名称，内容作为节点的文本内容<br />
[library]<br />
  [book]<br />
    [author]aaa[/author]<br />
    [year]2008[/year]<br />
    [title]Hello[/title]<br />
  [book]<br />
  [book]<br />
    [author]bbb[/author]<br />
    [year]2007[/year]<br />
    [title]World[/title]<br />
  [book]<br />
[/library]</p>
<p>将上面的方括号看作尖括号。不知道是否回答了你的问题？</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：zhangxiaoqiang</title>
		<link>http://tech.idv2.com/2008/09/03/perl-xml-simple/comment-page-1/#comment-11416</link>
		<dc:creator>zhangxiaoqiang</dc:creator>
		<pubDate>Mon, 15 Dec 2008 02:05:59 +0000</pubDate>
		<guid isPermaLink="false">http://tech.idv2.com/2008/09/03/perl-xml-simple/#comment-11416</guid>
		<description>顺便问一下，将一个xml文件的节点设成一个表的字段，节点的属性值作为字段的内容
格式： 字段：A&#124;B&#124;C&#124;D
      内容：a&#124;b&#124;c&#124;d

没有思路啊！</description>
		<content:encoded><![CDATA[<p>顺便问一下，将一个xml文件的节点设成一个表的字段，节点的属性值作为字段的内容<br />
格式： 字段：A|B|C|D<br />
      内容：a|b|c|d</p>
<p>没有思路啊！</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：zhangxiaoqiang</title>
		<link>http://tech.idv2.com/2008/09/03/perl-xml-simple/comment-page-1/#comment-11415</link>
		<dc:creator>zhangxiaoqiang</dc:creator>
		<pubDate>Mon, 15 Dec 2008 01:51:25 +0000</pubDate>
		<guid isPermaLink="false">http://tech.idv2.com/2008/09/03/perl-xml-simple/#comment-11415</guid>
		<description>呵呵，谢谢啦，是像你说的那样！</description>
		<content:encoded><![CDATA[<p>呵呵，谢谢啦，是像你说的那样！</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：charlee</title>
		<link>http://tech.idv2.com/2008/09/03/perl-xml-simple/comment-page-1/#comment-11354</link>
		<dc:creator>charlee</dc:creator>
		<pubDate>Thu, 04 Dec 2008 12:24:58 +0000</pubDate>
		<guid isPermaLink="false">http://tech.idv2.com/2008/09/03/perl-xml-simple/#comment-11354</guid>
		<description>@zhangxiaoqiang 如果你用的程序和我的完全一样的话，那么程序里打开文件用的是&#039;sample.xml&#039;，没有指定路径，所以它指的是当前目录下的sample.xml。而你的当前目录是 D:\perl\bin，所以它会去找 D:\perl\bin\sample.xml，当然找不到了。
你应当先cd到 e:\perl，然后再运行 perl sample.pl</description>
		<content:encoded><![CDATA[<p>@zhangxiaoqiang 如果你用的程序和我的完全一样的话，那么程序里打开文件用的是&#8217;sample.xml&#8217;，没有指定路径，所以它指的是当前目录下的sample.xml。而你的当前目录是 D:\perl\bin，所以它会去找 D:\perl\bin\sample.xml，当然找不到了。<br />
你应当先cd到 e:\perl，然后再运行 perl sample.pl</p>
]]></content:encoded>
	</item>
</channel>
</rss>
