Preparation of carboxylic acids or their salts, halides or anhydrides by oxidation with halogen-containing compounds which may be formed in situ