| | 910 | Nodes are entities in the YAML informational model. There are three kinds of nodes: |
| | 911 | ''scalar'', ''sequence'', and ''mapping''. In PyYAML, nodes are produced by Composer |
| | 912 | and can be serialized to a YAML stream by Serializer. |
| | 913 | |
| | 914 | {{{ |
| | 915 | #!python |
| | 916 | ScalarNode(tag, value, style, start_mark, end_mark) |
| | 917 | SequenceNode(tag, value, flow_style, start_mark, end_mark) |
| | 918 | MappingNode(tag, value, flow_style, start_mark, end_mark) |
| | 919 | }}} |
| | 920 | |
| | 921 | The '''`style`''' and '''`flow_style`''' flags have the same meaning as for events. |
| | 922 | The value of a scalar node must be a unicode string. The value of a sequence node is |
| | 923 | a list of nodes. The value of a mapping node is a dictionary which keys and values |
| | 924 | are nodes. |
| | 925 | |
| | 926 | Example: |
| | 927 | {{{ |
| | 928 | #!python |
| | 929 | >>> print yaml.compose(""" |
| | 930 | ... kinds: |
| | 931 | ... - scalar |
| | 932 | ... - sequence |
| | 933 | ... - mapping |
| | 934 | ... """) |
| | 935 | |
| | 936 | MappingNode(tag=u'tag:yaml.org,2002:map', value={ |
| | 937 | ScalarNode(tag=u'tag:yaml.org,2002:str', value=u'kinds'): SequenceNode(tag=u'tag:yaml.org,2002:seq', value=[ |
| | 938 | ScalarNode(tag=u'tag:yaml.org,2002:str', value=u'scalar'), |
| | 939 | ScalarNode(tag=u'tag:yaml.org,2002:str', value=u'sequence'), |
| | 940 | ScalarNode(tag=u'tag:yaml.org,2002:str', value=u'mapping')])}) |
| | 941 | |
| | 942 | >>> print yaml.serialize(yaml.SequenceNode(tag=u'tag:yaml.org,2002:seq', value=[ |
| | 943 | ... yaml.ScalarNode(tag=u'tag:yaml.org,2002:str', value=u'scalar'), |
| | 944 | ... yaml.ScalarNode(tag=u'tag:yaml.org,2002:str', value=u'sequence'), |
| | 945 | ... yaml.ScalarNode(tag=u'tag:yaml.org,2002:str', value=u'mapping')])) |
| | 946 | |
| | 947 | - scalar |
| | 948 | - sequence |
| | 949 | - mapping |
| | 950 | }}} |