Doug S.
Doug S.

Reputation: 682

How to structure this xml?

Lets say I am working on an xml file for super hero groups and my xml looked like this -

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet href="sh.xsl" type="text/xsl" ?>
<superheroGroups>
    <group>
        <title>X-Men</title>
        <name>Wolverine</name>
        <name>Cyclops</name>
        <name>Jean Grey</name>
        <name>Storm</name>
    </group>
    <group>
        <title>Runaways</title>
        <name>Alex Wilder</name>
        <name>Nico Minoru</name>
        <name>Karolina Dean</name>
        <name>Gertrude Yorkes</name>
        <name>Chase Stein</name>
        <name>Molly Hayes</name>
    </group>
    <group>
        <title>Avengers</title>
        <name>Iron Man</name>
        <name>Ant Man</name>
        <name>Wasp</name>
        <name>Hulk</name>
        <name>Captain America</name>
    </group>
    <group>
        <title>Fantastic Four</title>
        <name>Mr Fantastic</name>
        <name>Invisible Woman</name>
        <name>Human Torch</name>
        <name>Thing</name>
    </group>
</superheroGroups>

Does this look correct or is my structure flawed? Should all of the heroes in a group be in a node under Members?

Upvotes: 0

Views: 55

Answers (2)

Jon Skeet
Jon Skeet

Reputation: 1500903

It's up to you how you structure it - but personally I'd probably make the title of each group an attribute:

<group title="Avengers">
    <name>Iron Man</name>
    <name>Ant Man</name>
    <name>Wasp</name>
    <name>Hulk</name>
    <name>Captain America</name>
</group>

And sometimes working with attributes can be simpler than working with content anyway:

<group title="Avengers">
    <member name="Iron Man" />
    <member name="Ant Man" />
    <member name="Wasp" />
    <member name="Hulk" />
</group>

Upvotes: 3

Giedrius
Giedrius

Reputation: 8540

I would move heroes to separate node, for simpler serialization/deserialization, or make a title as an attribute.

Upvotes: 0

Related Questions