Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've never been very good at maintaining a coherent bunch of variable names for interfacing with XML files because I never name the variables in my interfaces the same way across my source.

There are Elements, Attributes, Documents, NodeLists, Nodes, DocumentFragments and other stuff. What's a good scheme for keeping track of this stuff as variables?

Is there a standard in regard to Hungarian notation? Do you even put anything signifying that the data is actually XML, is this bad practice?

Also, what is the difference between the way you name your constants (signifying Namespaces, Elements and Attribute Names) and your variables (signifying Namespaces, Elements, Attributes, Nodes, Node Lists and Documents)

share|improve this question
up vote 4 down vote accepted

It's unclear whether you're asking about the variables that you use in code to hold values retrieved from an XML file, or variables used to refer to parts of the file itself. In the former case, I don't see why you'd care that the data came from XML versus, say, a database.

In the latter case, I defined constants to refer to the various elements and attributes, to keep literal values out of my code. Constants for elements all start with EL_, attributes all start with AT_, and namespaces all start with NS_. Those are really the only three things that I'm likely to access by name. If there are multiple classes that need to access the same XML structures, the constants get moved to a common support class.

Of course, that leads to some ugliness elsewhere. For example, constructing XPath expressions out of those constants is less clear (I think) than literals. And you have to ensure that the constants and any external validations (such as DTD or Schema) remain in sync.

share|improve this answer

I personally use names like

docNode, rootElem, customAttr
and the like. There's definitely not a method for it in Hungarian Notation because they're all different objects and their implementations can be wildly different across various XML packages, unlike say a Boolean.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.