0

Is it possible to set and retrieve default values in an XML hierarchy.

    <commission-rate>
        <region-NA> <!-- can we set a default at this level, if userId is NOT 123, it should return this default -->
            <userId-123>
                9
            </userId-123>
        </region-NA>
    </commission-rate>

For example, if I want to retrieve commission-rate.region-NA, it should return the default (say 5), but commission-rate.region-NA.userId-123 should pull 9 as the value.

Also, is using XML tags like this recommended or I should be using named attributes (e.g.

Thanks in advance.

Swapnil
  • 8,201
  • 4
  • 38
  • 57

1 Answers1

1

For your first question:

XML document on its own does not contain any default values. It just contains the values that the document contains. Everything else is undefined.

For your second question:

Please see: How should you structure your xml file?

Community
  • 1
  • 1
hakre
  • 193,403
  • 52
  • 435
  • 836
  • Got your point. What I mean is - Is it possible to set anything as default at the tag , or I need to include an element like 5 – Swapnil Dec 13 '12 at 07:54
  • 1
    That is all up to you, there is no "default" you can set inside the XML document. So it's likely that you will create your own element like 5 to carry your wished default value. – hakre Dec 13 '12 at 07:58