Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm studying YAML as a replacement for XML, but I'm experiencing difficulties when dealing with elements containing free-flowing text with embedded elements. For instance, the following XML document:

    <text>
    This is an example text, spanning multiple lines, and it has embedded elements
    like <a p="value">this</a> and <b>this</b>.  There is also a list:
         <quote>
            <text>The text of the quote, spanning multiple lines, and it has
            embedded elements like <c p="value">this</c> and <b>this</b></text>
            <author>The Author of this quote</author>
        </quote>
    Text continues here.
    </text>

I don't know how to convert the embedded elements in YAML. My understanding is that the above XML document translates to something like this (except for the embedded elements):

    text: >
            This is an example text, spanning multiple lines, and it has embedded
            elements like <a p="value">this</a> and <b>this</b>.  There is also a
            list:
                 quote:
                    text: > 
                            The text of the quote, spanning multiple lines,
                            and it has embedded elements like <c p="value">this</c>
                            and <b>this</b>
                    author: The Author of this quote
            Text continues here.

Also, is indentation not needed in some places?

Thank you.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

The YAML website describes YAML in the following terms:

YAML: YAML Ain't Markup Language

What It Is: YAML is a human friendly data serialization
  standard for all programming languages.

You probably don't want YAML for this. YAML is meant to be used to save data out to files for future retrieval, basically as a form of serialization. The major benefit it has over XML in this regard is the fact that he lacks the clutter of XML's angle brackets and end tags. It's easy to read and edit for humans. XML, on the other hand, is already designed to work with an HTML-like syntax. XML's major purpose is as a markup language.

You could look at it this way:

  • Use YAML when you want to save text or objects to a file.
  • Use XML when you want to provide markup for documents
share|improve this answer
    
I though YAML had the same capabilities as XML, but with a light-weight syntax similar to text. If I have to resort to quoted strings and the likes, then I misunderstood its use. Thank you. –  Elena Jul 19 '12 at 15:27
    
It has similar capabilities, but it's primarily meant for modelling object data, NOT marking up websites. It was basically created to make it easier to do the sort of config files and data storage that people were trying to do with XML (which was never XML's intended purpose) –  KChaloux Jul 19 '12 at 16:53
    
So the answer is: what I'm trying to do cannot be done. Thanks. –  Elena Jul 19 '12 at 18:15
2  
It probably CAN be done, with enough futzing and fiddling. I just don't think YAML is particularly suited for the task. –  KChaloux Jul 19 '12 at 19:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.