<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def serialize(self, *fields):
 """Serialize Nodes and attributes """

        if fields:
            if not set(fields).issubset(self.data_nodes):
                raise SchemaError('Invalid field for serialization: {}'.format(set(fields).difference(self.data_nodes)))

            return OrderedDict([(k, getattr(self, k)) for k in fields])

        return OrderedDict([(k, getattr(self, k)) for k in self.data_nodes])