tags:

views:

41

answers:

3

I am designing XML for some custom logging. There's a part in the logger where the developer can add name-value pairs to the log. I'm trying to decide how the XML should look. I'm trying to decide whether the name portion of the name value pair should be an attribute. (I think so). Here's what I have so far:


<ExtendedProperties>
   <ExtendedProperty name="Name1">Value1</ExtendedProperty>
   <ExtendedProperty name="Name2">Value2</ExtendedProperty>
</ExtendedProperties

The other option (that I know of) is to make the value name the node name:

<Name1>Value1</Name1>
<Name2>Value2</Name2>

I like the first method (attribute based) better because I can more easily describe the document with XSD, and I can see how you could use xpath or xquery to access all of the elements of type "ExtendedProperty". (The available names are not predefined -- they could be anything. )

However, I don't spend much time developing XML schemas. Does that look right to you guys? Is there anything else that I might want to consider?

A: 

If you're going with a key-value pair collection of elements, your first option is the way to go.

In that case, your element is the name of the type of item in the collection...your attribute is the key...and the value is the value.

For example:

<StringCollection>
    <String name="stringOne">Something</String>
    <String name="stringTwo">Something else</String>
</StringCollection>

Your second way would be a non-grouped set of non-related elements...not what you want.

Justin Niessner
A: 

Looks good. You can also (if values are simple) include support for short form <ExtendedProperty name="name" value="value" />. That's how it's done in Spring config for example

DroidIn.net
+2  A: 

The available names are not predefined -- they could be anything.

This makes it impossible to use the 2nd form (with xml-schema) - since you need to know all the valid names using that method

sylvanaar