|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
Note: This is an unedited contribution. If this article is inappropriate,
needs attention or copies someone else's work without reference then please
Report This Article
IntroductionYAML is a human-friendly, cross language, Unicode based data serialization language designed around the common native data types of agile programming languages. It is broadly useful for programming needs ranging from configuration files to Internet messaging to object persistence to data auditing. Visit Official YAML Web Site for more information. YAML BisicOne YAML file may contain zero or more YAML documents, separated by document markers. One YAML document contains one root DataItem. There are three types of DataItems: Scalar, Sequence and Mapping. DataItems may be nested to form structured data. Each DataItem type has several formatting styles for good humun readability.
Some rules: Block style item can be nested to block style item but not flow style item. Here are some examples: Block Scalar: Literal Text
Folded Text
Flow Scalar
Sequence:
Mapping:
Other: Anchor and Alias
Comment
BackgroundThere is already a Yaml Library for .NET project, but the features supported are limited. Using the codeThe parser code is generated using a homemade tool based on grammar specified in YAML.PEG.txt file. This grammar is not completely equal to the official YAML Specification. Here are some differences: A separator “ The parser can be used like this:
YamlParser parser = new YamlParser();
TextInput input = new TextInput(File.ReadAllText(yamlFilePath));
bool success;
YamlStream yamlStream = parser.ParseYamlStream(input, out success);
if (success)
{
foreach (YamlDocument doc in yamlStream.Documents)
{
// access DataItem by doc.Root
}
}
else
{
MessageBox.Show(parser.GetEorrorMessages());
}
Or: YamlStream yamlStream = YamlParser.Load(yamlFilePath);
Points of interestThe main shortcomming of this parser is that error messages are not intuitive. Welcome to give suggestions. History
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||