user1276858
user1276858

Reputation: 41

Transforming XML to ruby code

What's a good way to transform XML to ruby code? I've got a GraphML file containing information about a graph structure. I want to instantiate a graph from that with ruby objects.

Currently I use XPath to do this in a procedural way. I know, there's also a way to do it with XSLT in a more declarative way.

Do you know other ways? What would you suggest, any experience?

Upvotes: 2

Views: 186

Answers (1)

Ryan Porter
Ryan Porter

Reputation: 2182

I don't quite understand why you would want to transform the GraphML data into Ruby code, rather than using Ruby to parse the GraphML data into Ruby object instances?

I made this example as an exercise: https://github.com/endymion/GraphML-parsing-exercise

It uses Nokogiri to parse the XML, then XPath to select nodes, then it iterates through the nodes, instantiating Ruby object instances: https://github.com/endymion/GraphML-parsing-exercise/blob/master/parse.rb

Is that roughly what you're looking for?

Upvotes: 1

Related Questions