Wednesday, November 9, 2011

[new portable algo] Easy XML Parsing using XML-Motor (currently just in Ruby)

Easy XML Parsing using XML-Motor 
(currently just implemented in Ruby as a Gem)
Using a new, compact algorithm of XML Partsing

===================================================
v 0.0.2
@GitHub: https://github.com/abhishekkr/rubygem_xml_motor

@RubyGems: http://rubygems.org/gems/xml-motor
===================================================

A new short XML Parsing Algorithm implemented in LessThan 200 Ruby lines.
An easy-to-use XML Parser without any Native Dependencies.

[How To Use]

Installing and Loading:
   + $ gem install xml-motor
   + in your ruby code: require 'xml-motor'

Usage:
  + To find values of an xml node from an xml file
      XMLMotor.get_node_from_file [file_name_with_path], [tag_name]
  + To find values of an xml node from an xml string
      XMLMotor.get_node_from_content [xml_data], [tag_name]
  + To find values of an xml node with a tag_name having required attribute
      XMLMotor.get_node_from_content [xml_data], [tag_name], [attr_key=attr_value]

Example Calls As Code:
 + XMLMotor.get_node_from_content "<A i='1'>a<A><B>b<C>c<C><A>ba<A><B>", "A"
     RETURNS: ["a", "ba"]
 + XMLMotor.get_node_from_content "<A i='1'>a<A><B>b<C>c<C><A>ba<A><B>", "B.A"
     RETURNS: ["ba"]
 + XMLMotor.get_node_from_content "<A i='1'>a<A><B>b<C>c<C><A>ba<A><B>", "A", "i='1'"
     RETURNS: ["a"]

===================================================

[Example Code]

require 'xml-motor'

puts XMLMotor.get_node_from_file "eloqjs.htm", "h1"
 
fyl = File.open("elogjs.htm")
XMLData = fyl.read

puts XMLMotor.get_node_from_content XMLData, "div.span"

puts XMLMotor.get_node_from_content XMLData, "div"

===================================================

No comments:

Post a Comment