xml-motor
what, why & how about the new technique xml-parser rubygem
http://justfewtuts.blogspot.com/2012/03/xml-motor-what-it-is-how-why-should-you.html
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
xml-motor ~ What,Why,How
1. xmlmotor
What it is : slide#2
Why you should use it : slide#3-6
How to use it : slide#7-12
AbhishekKr
http://www.twitter.com/aBionic
http://github.com/abhishekkr
2. Late 2011, started a new rubygem project for parsing xml, html.
@Rubygems: http://rubygems.org/gems/xml-motor
@GitHub : https://github.com/abhishekkr/rubygem_xml_motor
Just created it to test out my work at compact, quick &
easy xmlparsing algorithm... can see that
@Slideshare: http://www.slideshare.net/AbhishekKr/xmlmotor
So, currently this is a nonnative, completely independent
lessthan250 rubyLOC available as a simple rubygem to
be required and use in an easy freehand notation (like
'div.img') and match with any/multiple node attributes (like
'id=”a1”' or ['type=”color”', 'name=”white”']).
3. Current Features
● Has a single method access to parse require xml nodes from
content or file.
● Use it only if you are gonna parse that xmlcontent once.
● For using same xmlcontent more than once, follow the 3way
step mentioned in examples on end slides.
● It doesn't depend on presence of any other system library,
purely nonnative.
● It parses broken or corrupted xml/html content correctly, just
for the content it have.
● Can parse results on looking for nodenames, attributes of
node or both.
7. USAGE
code we are going to try:
https://github.com/abhishekkr/axml-motor/tree/master/ruby/examples
8. say, you have an xml file 'dummy.xml', with data as
<dummy>
<ummy>
<mmy class='sys'>non-native</mmy>
</ummy>
<ummy>
<mmy class='sys'>
<my class='sys' id='mem'>compact</my>
</mmy>
</ummy>
<mmy type='user'>
<my class='usage'>easy</my>
</mmy>
</dummy>
9. its available at rubygems.org, install it as
$ gem install xmlmotor
include it in your ruby code,
#!/usr/bin/env ruby
require 'xmlmotor'
get the XML Filename and/or XML data
available
fyl = File.join(File.expand_path
(File.dirname __FILE__),'dummy.xml')
xml = File.open(fyl,'r'){|fr| fr.read }
11. Way to go for XML-Parsing for xml node searches
xsplit = XMLMotor.splitter xml
xtags = XMLMotor.indexify xsplit
[] just normal node name based freehand notation
to search:
XMLMotor.xmldata
(xsplit, xtags, 'dummy.my')
Result: ["compact", "easy"]
[] searching for values of required nodes filtered
by attribute:
XMLMotor.xmldata
(xsplit, xtags, nil, 'class="usage"')
Result: ["easy"]
12. [] searching for values of required nodes filtered by
freehand tag-name notation & attribute:
XMLMotor.xmldata(xsplit, xtags,
'dummy.my', 'class="usage"')
Result: ["easy"]
[] searching for values of required nodes filtered by
freehand tag-name notation & multiple attributes:
XMLMotor.xmldata(xsplit, xtags,
'dummy.my', ['class="sys"', 'id="mem"'])
Result: ["compact"]