Ruby & Ruby on rails : Rexml 파싱 :: 2009/02/16 00:00
[참고:Rails for Java Developers]
xml 파싱 중, 푸시파싱과 풀파싱. 둘다 순서대로 한방향으로 이동하며 처리되는 로직이다.
트리파싱은 전체 문서를 불러들이고 무작위로 접근. 복잡한 문서활용때 효과증가.
푸시파싱//
require 'rexml/parsers/sax2parser'
include REXML::Parsers
targets = []
xml ='<data><type name="a">test1</type>
<type name="b">test2</type>
<type name="c">test3</type></data>'
parser = SAX2Parser.new(xml)
parser.listen(:start_element, %w{type}) do |u,l,q,atts|
targets << {:name=>atts['name']}
end
parser.parse
puts targets
=>namea
nameb
namec
##여기서 %w{}는 배열 생성자
풀파싱//
require 'rexml/parsers/pullparser'
include REXML::Parsers
targets = []
xml ='<data><type name="a">test1</type>
<type name="b">test2</type>
<type name="c">test3</type></data>'
parser = PullParser.new(xml)
parser.each do |e|
if e.start_element? and e[0] == 'type'
targets << {:name=>e[1]['name']}
end
end
puts targets
=>namea
nameb
namec
트리파싱//
require 'rexml/document'
include REXML
targets = []
xml ='<data><type name="a">test1</type>
<type name="b">test2</type>
<type name="c">test3</type></data>'
Document.new(xml).elements.each("//type") do |e|
targets << {:name=>e.attributes["name"]}
end
puts targets
=>namea
nameb
namec
빌더로 xml 생성
require 'rubygems'
require 'builder'
xml = Builder::XmlMarkup.new :type=>STDOUT, :indent=>1
xml.data do
xml.type "test1", :name=>"a"
xml.type "test2", :name=>"b"
xml.type "test3", :name=>"c"
end
puts xml.to_ary
=><data>
<type name="a">test1</type>
<type name="b">test2</type>
<type name="c">test3</type>
</data>
<to_ary/>
##레일스에 기본적으로 내장되어있는 줄 알고 있었는데, 새로 설치해야 했다. 그럴 경우 gem install builder로 설치
rails 1.x 버전은 require_gem, 2.x 버전은 그냥 require로...
[기타정보]
rexml 공식 // http://www.germane-software.com/software/rexml/
rexml api reference //
http://docs.huihoo.com/rdoc/ruby/stdlib/libdoc/rexml/rdoc/index.html
builder reference // http://builder.rubyforge.org/
-
Buy percocet online.
Tracked from Buy percocet online. | 2010/06/22 01:38 | DELBuy percocet online.
-
Duromine description.
Duromine picture. Duromine identification. Duromine.
-
Purchase hydrocodone online.
Tracked from Hydrocodone. | 2010/06/23 01:04 | DELHydrocodone apap. Hydrocodone. Effects of hydrocodone. Hydrocodone drug testing.
-
Liquid codeine how to make.
Codeine.
-
Buy morphine without rx.
Tracked from Buy morphine from mexico. | 2010/06/24 00:08 | DELBuy morphine from mexico. Buy morphine. Buy morphine no prescription. Buying morphine in mexico. Buy morphine online.
-
Buy zolpidem.
Tracked from Buy zolpidem. | 2010/06/24 13:28 | DELBuy zolpidem.
-
Valium.
Tracked from Liquid valium. | 2010/06/25 00:36 | DELValium side effects. Xanax valium. Buy valium c.o.d.. Liquid valium. Side effects of valium. Valium.
-
Casino 1277409639
Tracked from Casino 1277409639 | 2010/06/25 05:33 | DELCasino 1277409639
-
Buy meridia buy cheap meridia online.
Tracked from Buy meridia buy cheap meridia online. | 2010/06/25 14:12 | DELBuy meridia buy cheap meridia online. Where can i buy meridia cheap. Meridia information gt gt buy meridia. Xenical meridia gt gt buy meridia. Pillinc buy phentermine adipex meridia online. Buy meridia.
-
Generic fioricet.
Tracked from Purchase fioricet online without prescription. | 2010/06/26 03:09 | DELGeneric fioricet. Order fioricet. Buy fioricet.
-
Adderall treating anxiety in adults.
Adderall xr side effects. Dexadrine adderall comparison. Adderall. Adderall without a prescription. Adderall abuse.
-
Casino 1277570081
Tracked from Casino 1277570081 | 2010/06/27 03:56 | DELCasino 1277570081
-
Cialis.
Tracked from Buy viagra online uk cialis levitra. | 2010/06/28 11:59 | DELCialis lawyers. Cialis.
-
Effect of vicodin.
Affects of vicodin. Vicodin.
-
Easy way to buy hydrocodone online.
Tracked from Search hydrocodone online without a prescription. | 2010/06/29 11:55 | DELHydrocodone online. Buy hydrocodone online. Hydrocodone online cod. Buy hydrocodone online without a prescription. Purchase hydrocodone online. Hydrocodone and online and prescriptions. Hydrocodone online without a script.
-
Viagra patent.
Tracked from Discount viagra. | 2010/06/29 22:52 | DELViagra. Viagra prescription price. Female viagra. Taking viagra with cialis.
-
Lortab.
Tracked from Pics of lortab 10 750. | 2010/06/30 14:20 | DELPotent lortab percocet darvon. Lortab. Lortab side effects. Lortab erowid.
-
Levitra.
Why would he have levitra.. Buy levitra paypal. Which is more effective viagra cialas levitra. Levitra. Buy levitra online. Using levitra for eczema..
-
Ibuprofen.
Tracked from Ibuprofen dosage. | 2010/07/01 09:59 | DELIbuprofen liver damage. Ibuprofen. Ibuprofen and overdose. Perrigo ibuprofen recall.
-
Hydrocodone.
Tracked from Hydrocodone. | 2010/08/04 07:19 | DELHydrocodone. Hydrocodone apap. Buy hydrocodone online. Hydrocodone guaifenesin. Buy hydrocodone online without a prescription. Buy hydrocodone without a prescription.
-
Get vicodin from foreign pharmacies.
Tracked from Get vicodin from foreign pharmacies. | 2010/08/04 22:15 | DELGet vicodin from foreign pharmacies.
-
Buy hydrocodone.
Tracked from How to make hydrocodone. | 2010/08/05 09:00 | DELHydrocodone.
-
Buy adderall direct.
Tracked from Buy adderall direct. | 2010/08/06 09:31 | DELBuy adderall direct.
-
Buy soma.
Tracked from Buy soma online without rx. | 2010/08/07 08:07 | DELBuy soma online. Buy soma without prescription. Buy soma bloghoster. Buy soma watson brand online 150 tablets. Http pills.viptemplates.com p buy soma. Buy watson brand soma. Cyclobenzaprine buy prescription soma zanaflex.
-
Buy valium online without a prescription.
Tracked from Buy valium online. | 2010/08/08 07:24 | DELValium cheap online september.
-
Get vicodin from foreign pharmacies.
Tracked from Get vicodin from foreign pharmacies. | 2010/08/08 17:10 | DELGet vicodin from foreign pharmacies.
-
Ativan ems usps.
Tracked from Ativan ems usps. | 2010/08/10 06:10 | DELAtivan ems usps.
-
Get vicodin from foreign pharmacies.
Tracked from Get vicodin from foreign pharmacies. | 2010/08/10 07:09 | DELGet vicodin from foreign pharmacies.
-
Apo lorazepam.
Tracked from Lorazepam plo gel. | 2010/08/10 16:40 | DELLorazepam side effects. Lorazepam siezure r. Mg dosage of lorazepam. Buy lorazepam. Lorazepam.
-
Soma online soma buy soma online.
Tracked from Soma buy soma cheap soma soma online. | 2010/08/11 16:49 | DELBuy soma online order soma and get cheap soma. Buy soma online. Buy soma watson brand online 150 tablets. Soma buy soma cheap soma soma online.
-
Lorazepam.
Tracked from Lorazepam addiction. | 2010/08/12 07:20 | DELLorazepam dosage. Lorazepam and propylene glycol. Effect lorazepam side. Lorazepam r. Lorazepam.
-
Buy link online ca tf valium.
Tracked from Valium mexico online. | 2010/08/12 16:28 | DELOnline pharmacy valium cheap. Online no prescription valium.
-
Lorazepam.
Tracked from Lorazepam. | 2010/08/13 08:16 | DELAtivan lorazepam. Effect of lorazepam. Lorazepam.
-
Lorazepam.
Tracked from Lorazepam no prescription. | 2010/08/14 09:00 | DELLorazepam. Apo-lorazepam 1mg.
-
Ativan ems usps.
Tracked from Ativan ems usps. | 2010/08/14 09:18 | DELAtivan ems usps.
-
Get vicodin from foreign pharmacies.
Tracked from Get vicodin from foreign pharmacies. | 2010/08/15 01:08 | DELGet vicodin from foreign pharmacies.
-
Get vicodin from foreign pharmacies.
Tracked from Get vicodin from foreign pharmacies. | 2010/08/15 09:40 | DELGet vicodin from foreign pharmacies.
-
Buy soma bloghoster.
Tracked from Buy soma bloghoster. | 2010/08/15 18:20 | DELBuy cheap soma. Buy soma. Buy soma online. Buy soma watson brand online 150 tablets.
-
Buy hydrocodone.
Tracked from Buy hydrocodone. | 2010/08/16 07:32 | DELBuy hydrocodone without prescription. Buy hydrocodone. Buy hydrocodone without a prescription. Buy hydrocodone illegally.
-
Hydrocodone.
Tracked from Watson hydrocodone. | 2010/08/17 08:29 | DELEasy way to buy hydrocodone online. Taking low dose of hydrocodone while pregnant. Hydrocodone. Hydrocodone detection period. Buy hydrocodone. Hydrocodone guaifenesin syreth.
-
Buy xanax online.
Tracked from Buy xanax online. | 2010/08/21 05:25 | DELBuy xanax online. Xanax buy xanax online discoint xanax cheap. Buy no xanax online prescription all on one site.



