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”']).
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.
looks like, '<library>... <book> <title>ABC</title> <author>CBA</author> </book>... <book> <title>XYZ</title> <authors> <author>XY</author><author>YZ</author> </authors> </book>... </library>' and you look for 'book.author', then, you'll get back ['CBA', 'XY', 'YZ']; What that means is the childnode could be at any depth in the parentnode. Default return mode is without the tags, there is a switch to get the nodes.
or multiple attributes can be provided. These attribute searches can be combined up with freehand node name searches. Readme (a bit weird, have to loosen it up): https://raw.github.com/abhishekkr/rubygem_xm l_motor/master/README
Limit over resultnodes retrieved from start/end of matching nodes. Multinode attributebased filter for a hierarchical node search. Add more common CSS Selector style, capability is already present using attribute based search... just need to add a mapping method.
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 }
= 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"]