问题描述:

I am new to ruby and XML. I have been given an XML file and asked to do some data manipulation in that.

For ex. consider the below XML file.

<?xml version="1.0" encoding="UTF-8"?>

<note>

<to> Tove</to>

<from>Jani</from>

<heading>Reminder</heading>

<body>Don't forget me this weekend!</body>

</note>

They are asking me to extract the the string which are inside the tags for ex "Tove", "Jani" and do some manipulation(for ex replacing "tove" with "john") on it and rewrite the data to same xml document.

I know ruby has a lot of gems and utilities and there must be a good utility to do it. If someone has any idea about any utility to do this work easily then just let me know.

And if there is no utility then if someone could give me some idea on how to proceed with it then it would be good.

网友答案:

One way is to use REXML that comes as part of the standard library.

Another way is to use Nokogiri (I would recommend using this).

Here are some good tutorials that will definitely help you:

  • http://ruby.bastardsbook.com/chapters/html-parsing/
  • https://blog.engineyard.com/2010/getting-started-with-nokogiri/
相关阅读:
Top