ruby 解析 xml

1.xml文件如下: <?xml version=”1.0″ encoding=”UTF-8″?> <dataroot xmlns:od=”urn:schemas-microsoft-com:officedata” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”book1.xsd” generated=”2008-12-28T19:12:24″> <book1> <bianhao>GAR001</bianhao> <name>计算机组装与维护教程</name> <借阅时间>2008-03-14T17:23:28</借阅时间> <author>刘瑞新</author> <publish>机械工业出版社</publish> <count>1</count> <language>中文</language> <manager>ctec</manager> </book1> <book1> <bianhao>GAR002</bianhao> <name>计算机接口技术</name> <借阅时间>2008-03-14T17:27:16</借阅时间> <author>刘星等</author> <publish>机械工业出版社</publish> <count>1</count> <language>中文</language> <manager>ctec</manager> </book1> <book1> <bianhao>GAR003</bianhao> <name>数值分析与算法</name> <借阅时间>2008-03-14T17:28:50</借阅时间> <author>徐士良</author> <publish>机械工业出版社</publish> <count>1</count> <language>中文</language> <manager>ctec</manager> </book1> </dataroot> ruby.rb文件内容: require ‘rexml/document’ xml =REXML::Document.new(File.open”1.xml” xml.each_element(‘//book1’) do |newbook| puts newbook.elements[‘bianhao’].text puts newbook.elements[‘name’].text puts newbook.elements[‘author’].text puts newbook.elements[‘publish’].text puts newbook.elements[‘count’].text puts newbook.elements[‘language’].text puts newbook.elements[‘manager’].text end转自: http://zmfbird.iteye.com/blog/306174学会技能是小智慧,学会做人是大智慧。

ruby 解析  xml

相关文章:

你感兴趣的文章:

标签云: