views:

152

answers:

5
    <?xml version="1.0" encoding="utf-8" ?>
<Countries>
  <Country>
    <ID>1</ID>
    <Name>Nepal</Name>
  </Country>
  <Country>
    <ID>2</ID>
    <Name>India</Name>
    <Country>
      <ID>3</ID>
      <Name>China</Name>
    </Country>
    <Country>
      <ID>4</ID>
      <Name>Bhutan</Name>
    </Country>
    <Country>
      <ID>5</ID>
      <Name>USA</Name>
    </Country>
  </Country>
</Countries>

with the use of DataSet() i am extracting just the name of the country and putting it into dropdownlist in asp.net. what is the point of having that ID tag? is it an xml requirement?

+3  A: 

Much of the time, an ID is a unique identifier. Say you wanted to have the possiblity that two countries could have the same name, then you would need an ID that is unique to each country. In your case, the ID does seem unnecessary, but keeping it in the file would be good practice.

Matthew Jones
+3  A: 

I don't know that XML requires it per se, but for a lot of manipulations it's best to have a key value that's unique to the record, and numbers are best for that. It sounds like for your purposes it's fine to discard that information, but wherever it was produced it covering its bases so to speak for other potential uses.

Alex Mcp
+2  A: 

It's a unique identifier, but in the case where you have country codes the code itself is usually unique anyway so it serves little purpose overall. It could be used as an indexer in the case where it is inconvenient to identify the individual record by name.

Harv
+7  A: 

It is not an XML requirement. It is likely there as a standard unique identifier. That way, if the name of the country ever changes (which seems to happen pretty frequently), that gives you the freedom to change it in this file without screwing up dependent data, as other data should be storing the ID, not the country name.

Another reason to use the ID, is that your application may need to display the same country name in different languages. Your application can then present the appropriate translated name to the user, but in terms of the data it stores once the user selects a country, that should strictly be based on ID.

RedFilter
A: 

The appearance of the node could be related to a number of possibilities, all stemming from the data schema.

'ID' is probably a column in a validCountry table, and the ID and Country columns are being selected.

You're putting this in a drop down for a reason. The user will select a country and presumably, some data will be inserted or updated. Should you store the country name or the ID in this new/updated row? You would probably want a foreign key, using the ID to reference the country. Otherwise you get into weird situations when a country changes its name, for instance.

In fact I would think you will want the ID for the value attribute of the entries in the drop down (at least that's how it's often done.)

grantwparks