From: David Masover Date: 2009-03-26T04:10:31+09:00 Subject: Re: Parsing xml Arun Kumar wrote: > Jason Roelofs wrote: > >> Better question: Why *wouldn't* you want to use an existing library? >> You'd have to spend months on your own before it even starts to make >> sense to use such a custom solution over an existing, tested, and >> heavily used library like libxml or nokigiri (and to be fair, >> Hpricot::XML, though it's more for HTML parsing than XML). >> >> Jason >> > > Hi, > One problem is compatability. Compatibility with what? > I'm developing an application that > extracts the xml tags from a url like 'http://www.shoe-g.com/index.rdf' > Yes, Nokogiri can read that. I'll bet Hpricot can, too -- maybe even REXML. Maybe you can find an example for me of an XML document that Nokogiri (libxml) can't read? > My > boss is strict of not using any complex libraries. Either this is some sort of test or interview question, to make sure you understand regular expressions... ...or, your boss doesn't know what he's talking about. The whole reason to use Ruby is to save yourself work. Suppose you want the contents of each title tag, just as an example: require 'mechanize' mech = WWW::Mechanize.new mech.get 'http://www.shoe-g.com/index.rdf' doc = Nokogiri(mech.page.body) titles = (doc / 'title').map(&:text) Ask your boss if it's really worth it to spend days or months trying to get it right, when you could be using five lines to download and parse it much more simply and accurately than a regular expression would allow. And if your boss insists, even after seeing this, you might want to start looking for a new job -- that one won't last long.