Example of hierarchical data representing a library system with sections, book categories, and books in JSON and XML formats


 Provide an example of hierarchical data representing a library system with sections, book categories, and books in JSON and XML formats.

Requirements:

  1. In your JSON example, include:

    • Library name
    • At least two sections (e.g., "Fiction" and "Non-Fiction")
    • Each section should have at least two book categories (e.g., "Mystery" and "Science" under Fiction)
    • Each category should list at least two books, including book details such as ID, title, and author.
  2. In your XML example, use a similar structure:

    • Represent the library as the root element.
    • Each section, category, and book should have its own XML tags.
    • Include the same details for each book as specified in the JSON example.
Example of Hierarchical Data in JSON

{
  "Library": "Central City Library",
  "Sections": [
    {
      "SectionName": "Fiction",
      "Categories": [
        {
          "CategoryName": "Mystery",
          "Books": [
            { "BookID": "M001", "Title": "The Hound of the Baskervilles", "Author": "Arthur Conan Doyle" },
            { "BookID": "M002", "Title": "Gone Girl", "Author": "Gillian Flynn" }
          ]
        },
        {
          "CategoryName": "Science Fiction",
          "Books": [
            { "BookID": "SF001", "Title": "Dune", "Author": "Frank Herbert" },
            { "BookID": "SF002", "Title": "Neuromancer", "Author": "William Gibson" }
          ]
        }
      ]
    },
    {
      "SectionName": "Non-Fiction",
      "Categories": [
        {
          "CategoryName": "Biography",
          "Books": [
            { "BookID": "B001", "Title": "The Diary of a Young Girl", "Author": "Anne Frank" },
            { "BookID": "B002", "Title": "Long Walk to Freedom", "Author": "Nelson Mandela" }
          ]
        },
        {
          "CategoryName": "Self-Help",
          "Books": [
            { "BookID": "SH001", "Title": "Atomic Habits", "Author": "James Clear" },
            { "BookID": "SH002", "Title": "The Power of Now", "Author": "Eckhart Tolle" }
          ]
        }
      ]
    }
  ]
}


Example of Hierarchical Data in XML

<Library name="Central City Library">
    <Section>
        <SectionName>Fiction</SectionName>
        <Category>
            <CategoryName>Mystery</CategoryName>
            <Books>
                <Book>
                    <BookID>M001</BookID>
                    <Title>The Hound of the Baskervilles</Title>
                    <Author>Arthur Conan Doyle</Author>
                </Book>
                <Book>
                    <BookID>M002</BookID>
                    <Title>Gone Girl</Title>
                    <Author>Gillian Flynn</Author>
                </Book>
            </Books>
        </Category>
        <Category>
            <CategoryName>Science Fiction</CategoryName>
            <Books>
                <Book>
                    <BookID>SF001</BookID>
                    <Title>Dune</Title>
                    <Author>Frank Herbert</Author>
                </Book>
                <Book>
                    <BookID>SF002</BookID>
                    <Title>Neuromancer</Title>
                    <Author>William Gibson</Author>
                </Book>
            </Books>
        </Category>
    </Section>
    <Section>
        <SectionName>Non-Fiction</SectionName>
        <Category>
            <CategoryName>Biography</CategoryName>
            <Books>
                <Book>
                    <BookID>B001</BookID>
                    <Title>The Diary of a Young Girl</Title>
                    <Author>Anne Frank</Author>
                </Book>
                <Book>
                    <BookID>B002</BookID>
                    <Title>Long Walk to Freedom</Title>
                    <Author>Nelson Mandela</Author>
                </Book>
            </Books>
        </Category>
        <Category>
            <CategoryName>Self-Help</CategoryName>
            <Books>
                <Book>
                    <BookID>SH001</BookID>
                    <Title>Atomic Habits</Title>
                    <Author>James Clear</Author>
                </Book>
                <Book>
                    <BookID>SH002</BookID>
                    <Title>The Power of Now</Title>
                    <Author>Eckhart Tolle</Author>
                </Book>
            </Books>
        </Category>
    </Section>
</Library>

No comments:

Post a Comment