mercredi 27 septembre 2017

Attribute presence generic check

My requirement is to parse on XML and populate an object. How do I automatically track if attribute xyz is present once the object is populated from the Xml. Please note that I will no longer have access to the parsed buffer after the object is populated. Hence I need some mechanism to know whether the attribute was present in XML and the same is populated in the object.

I have the below solution in my mind but not sure if anything more efficient possible. Also I am looking for a generic solution for this problem.

  • define a bit for each of the attribute in a class.

  • setter function should set that bit while parsing XML when attribute is present

  • getter function should check the bit before returning the attribute value by reference . It should return false when bit is not set

Aucun commentaire:

Enregistrer un commentaire