J
Johannes Grassler
Hello,
I've been having loads of fun trying to work out how to de-serialize
a YAML dump of a data base I'm working with. More to the point I need to
process the YAML dump as a tree to restore child-parent relations
between objects (i.e. knowing the parent node when recreating a child
node).
Here's the relevant excerpt from my code:
| tree = YAML.parse(raw) # raw is a string holding the YAML input
| tree.children.each { |child|
| restore_object(child) }
And here's my YAML input:
| --- !yaml.org,2002:GraphLabel
| attributes:
[...]
| network_elements:
| - !yaml.org,2002:NetworkElement
| attributes:
I.e. the YAML input is a tree with one '--- !yaml.org,2002:GraphLabel'
at its root, at least if I interpret the dashes/indentation notation
right (please correct me if I'm wrong; I've only begun to familiarize
myself with YAML recently).
I want to call restore_object() on all nodes of type
!yaml.org,2002:NetworkElement. According to
<http://yaml4r.sourceforge.net/doc/page/parsing_yaml_documents.htm>
the call to YAML.parse should yield a YamlNode object that's
effectively the root of a tree I can descend into using its children()
method.
This is not so, for:
a) I do not get an object of type YamlNode but of YAML::Syck::Map
This is very mysterious critter about which little is known:
<http://www.ruby-doc.org/stdlib-1.8.6/libdoc/yaml/rdoc/classes/YAML/Syck/Node.html>
b) While said mysterious object does have a children() method that
method returns nil instead of the list of
!yaml.org,2002:NetworkElement I was expecting.
Can anyone shed some light on the issue or, better yet provide pointers to
comprehensive documentation?
For <http://yaml4r.sourceforge.net> is pretty thin on parsing YAML as
object trees, and <http://www.ruby-doc.org> is even worse (most YAML
methods are "documented" by a method prototype and a body that consists
of "[Source]").
Cheers,
Johannes
I've been having loads of fun trying to work out how to de-serialize
a YAML dump of a data base I'm working with. More to the point I need to
process the YAML dump as a tree to restore child-parent relations
between objects (i.e. knowing the parent node when recreating a child
node).
Here's the relevant excerpt from my code:
| tree = YAML.parse(raw) # raw is a string holding the YAML input
| tree.children.each { |child|
| restore_object(child) }
And here's my YAML input:
| --- !yaml.org,2002:GraphLabel
| attributes:
[...]
| network_elements:
| - !yaml.org,2002:NetworkElement
| attributes:
I.e. the YAML input is a tree with one '--- !yaml.org,2002:GraphLabel'
at its root, at least if I interpret the dashes/indentation notation
right (please correct me if I'm wrong; I've only begun to familiarize
myself with YAML recently).
I want to call restore_object() on all nodes of type
!yaml.org,2002:NetworkElement. According to
<http://yaml4r.sourceforge.net/doc/page/parsing_yaml_documents.htm>
the call to YAML.parse should yield a YamlNode object that's
effectively the root of a tree I can descend into using its children()
method.
This is not so, for:
a) I do not get an object of type YamlNode but of YAML::Syck::Map
This is very mysterious critter about which little is known:
<http://www.ruby-doc.org/stdlib-1.8.6/libdoc/yaml/rdoc/classes/YAML/Syck/Node.html>
b) While said mysterious object does have a children() method that
method returns nil instead of the list of
!yaml.org,2002:NetworkElement I was expecting.
Can anyone shed some light on the issue or, better yet provide pointers to
comprehensive documentation?
For <http://yaml4r.sourceforge.net> is pretty thin on parsing YAML as
object trees, and <http://www.ruby-doc.org> is even worse (most YAML
methods are "documented" by a method prototype and a body that consists
of "[Source]").
Cheers,
Johannes