Article Options
Premium Sponsor
Premium Sponsor

 »  Home  »  .NET Newbie  »  Practical XML Usage  »  The Task
 »  Home  »  Data Programming  »  XML  »  Practical XML Usage  »  The Task
Practical XML Usage
by Gaidar Magdanurov | Published  08/20/2006 | .NET Newbie XML | Rating:
The Task

The Task

The task is to process XML data about famous band discographies in XML format (discography files): validate discography files against schema, transform them to HTML and different XML formats and allow the visual editing of those files. The sample discography file is presented below.

<?xml version="1.0" encoding="utf-8"?>
<discography band="The Beatles" firstYear="1963" lastYear="1964">
    <album>
        <title>Please Please Me</title>
        <year>1963</year>
        <label>Parlaphone</label>
        <songs>
            <song>I Saw Her Standing There</song>
            <song>Misery</song>
            <song>Anna (Go to Him)</song>
            <song>Chains</song>
            <song>Boys</song>
            <song>Ask Me Why</song>
            <song>Please Please Me</song>
            <song>Love Me Do</song>
            <song>P.S. I Love You</song>
            <song>Baby It's You</song>
            <song>Do You Want to Know a Secret</song>
            <song>A Taste of Honey</song>
            <song>There's a Place</song>
            <song>Twist and Shout</song>
        </songs>
    </album>
    <album>
        <title>With the Beatles</title>
        <year>1963</year>
        <label>Parlaphone</label>
        <songs>
            <song>It Won't Be Long</song>
            <song>All I've Got to Do</song>
            <song>All My Loving</song>
            <song>Don't Bother Me</song>
            <song>Little Child</song>
            <song>Till There Was You</song>
            <song>Please Mr. Postman</song>
            <song>Roll Over Beethoven</song>
            <song>Hold Me Tight</song>
            <song>You Really Got a Hold on Me</song>
            <song>I Wanna Be Your Man</song>
            <song>Devil in Her Heart</song>
            <song>Not a Second Time</song>
            <song>Money (That's What I Want)</song>
        </songs>
    </album>
</discography>

The output HTML file for this sample discography file should be as follows.

<html>
<head>
    <META http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>The Beatles</title>
</head>
<body>
    <h1>The Beatles - Discography (1963 - 1964)</h1>
    <h2>Please Please Me (Parlaphone, 1963)</h2>
    <ol>
        <li>I Saw Her Standing There</li>
        <li>Misery</li>
        <li>Anna (Go to Him)</li>
        <li>Chains</li>
        <li>Boys</li>
        <li>Ask Me Why</li>
        <li>Please Please Me</li>
        <li>Love Me Do</li>
        <li>P.S. I Love You</li>
        <li>Baby It's You</li>
        <li>Do You Want to Know a Secret</li>
        <li>A Taste of Honey</li>
        <li>There's a Place</li>
        <li>Twist and Shout</li>
    </ol>
    <h2>With the Beatles (Parlaphone, 1963)</h2>
    <ol>
        <li>It Won't Be Long</li>
        <li>All I've Got to Do</li>
        <li>All My Loving</li>
        <li>Don't Bother Me</li>
        <li>Little Child</li>
        <li>Till There Was You</li>
        <li>Please Mr. Postman</li>
        <li>Roll Over Beethoven</li>
        <li>Hold Me Tight</li>
        <li>You Really Got a Hold on Me</li>
        <li>I Wanna Be Your Man</li>
        <li>Devil in Her Heart</li>
        <li>Not a Second Time</li>
        <li>Money (That's What I Want)</li>
    </ol>
</body>
</html>

And the output XML file should be as in the following.

<?xml version="1.0" encoding="utf-8" ?>
<disco>
    <description>
        <name>The Beatles</name>
        <firstYear>1963</firstYear>
        <lastYear>1964</lastYear>
    </description>
    <albums>
        <album>
            <title>Please Please Me</title>
            <label>Parlaphone</label>
            <year>1963</year>
            <songs>
                <title>I Saw Her Standing There</title>
                <title>Misery</title>
                <title>Anna (Go to Him)</title>
                <title>Chains</title>
                <title>Boys</title>
                <title>Ask Me Why</title>
                <title>Please Please Me</title>
                <title>Love Me Do</title>
                <title>P.S. I Love You</title>
                <title>Baby It's You</title>
                <title>Do You Want to Know a Secret</title>
                <title>A Taste of Honey</title>
                <title>There's a Place</title>
                <title>Twist and Shout</title>
            </songs>
        </album>
        <album>
            <title>With the Beatles</title>
            <label>Parlaphone</label>
            <year>1963</year>
            <songs>
                <title>It Won't Be Long</title>
                <title>All I've Got to Do</title>
                <title>All My Loving</title>
                <title>Don't Bother Me</title>
                <title>Little Child</title>
                <title>Till There Was You</title>
                <title>Please Mr. Postman</title>
                <title>Roll Over Beethoven</title>
                <title>Hold Me Tight</title>
                <title>You Really Got a Hold on Me</title>
                <title>I Wanna Be Your Man</title>
                <title>Devil in Her Heart</title>
                <title>Not a Second Time</title>
                <title>Money (That's What I Want)</title>
            </songs>
        </album>
    </albums>
</disco>

I am very sorry for the lengthy listings but they should give you the idea of what are we going to get in the end.

 

Sponsored Links