I have a server-side javascript file that translates an XML request to a JSON response (and vice-versa) and performs some business logic.
The XML element names come from a schema that is part of a different project.
To prevent minor typo's from causing major bugs, and to make dealing with schema changes relatively painless, I would like to extract the element names to variables.
In Java, I would either use variables of the type static final String or an enum to do this.
public class Names {
public final static String CUSTOMER_ZIPCODE = "POstal_code";
public final static String CUSTOMER_LASTNAME = "last-name";
public final static String EMPLOYEE_LASTNAME = "lastName";
}
Now when element names change in the schema, I just update the Names class. (Notice also the real-world inconsistent spelling of elements.)
The variables can then be used:
createElement(Names.CUSTOMER_LASTNAME, "Spolsky");
Resulting in:
<bla:last-name>Spolsky</bla:last-name>
Is there any way to do this is javascript?