Click here to Skip to main content
15,884,043 members
Articles / Programming Languages / C#

YAML Parser in C#

Rate me:
Please Sign up or sign in to vote.
4.83/5 (26 votes)
17 Feb 2011CPOL2 min read 329.8K   4.5K   70  
An almost feature complete YAML parser.
%YAML 1.2
---
- Mark McGwire
- Sammy Sosa
- Ken Griffey
---
hr : 65    # Home runs
av,g: 0.278 # Batting average
r, bi: 147   # Runs Batted In
---
american:
  - Boston Red Sox
  - Detroit Tigers
  - New York Yankees
national:
  - New York Mets
  - Chicago Cubs
  - Atlanta Braves
---
-
  name: Mark McG
  hr:   65
  avg:  0.278
-
  name: Sammy So
  hr:   63
  avg:  0.288
---
- [name        , hr, avg  ]
- [Mark McGwire, 65, 0.278]
- [Sammy Sosa  , 63, 0.288]
---
Mark McGwire: {hr: 65, avg: 0.278}
Sammy Sosa: {
    hr: 63,
    avg: 0.288
  }
---
# Ranking of 1998 home runs
- Mark McGwire
- Sammy Sosa
- Ken Griffey
# Team ranking
---
- Chicago Cubs
- St Louis Cardinals
---
time: 20:03:20
player: Sammy Sosa
action: strike (miss)
...
---
time: 20:03:47
player: Sammy Sosa
action: grand slam
...
---
hr: # 1998 hr ranking
  - Mark McGwire
  - Sammy Sosa
rbi:
  # 1998 rbi ranking
  - Sammy Sosa
  - Ken Griffey
---
hr:
  - Mark McGwire
  # Following node labeled SS
  - &SS Sammy Sosa
rbi:
  - *SS # Subsequent occurrence
  - Ken Griffey  
---
? - Detroit Tigers
  - Chicago cubs
:
  - 2001-07-23
? [ New York Yankees,
    Atlanta Braves ]
: [ 2001-07-02, 2001-08-12,
    2001-08-14 ]
---
# products purchased
- item    : Super Hoop
  quantity: 1
- item    : Basketball
  quantity: 4
- item    : Big Shoes
  quantity: 1    
# ASCII Art
--- |
  \//||\/||
  // ||  ||__  
        # ASCII Art
---
  Mark McGwire's
  year was crippled
  by a knee injury.  
---
>
 Sammy Sosa completed another
 fine season with great stats.
  63 Home Runs
 0.288 Batting Average
 What a year!
---
name: Mark McGwire
accomplishment: >
 Mark set a major league
 home run record in 1998.
stats: |
 65 Home Runs
 0.278 Batting Average  
---
unicode: "Sosa did fine."
single: '"Howdy!" he cried.'
quoted: ' # not a ''comment''.'
tie-fighter: '|\-*-/|'
---
"Fun with \\\" \a \b \e \f \
\n \r \t \v \0 \
\  \_ \N \L \P \
\x41 \u0041"

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect YunCheDa Hangzhou
China China
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions