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)

2 Answers 2


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.


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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