I have a business requirement, which says that xml files (with table and row like elements) are attached (uploaded) to a custom object, which will be done through the REST API. That's done. Now I would need to open that attachment by code (could also be a file object) and read parts of that xml file into a custom object, and then send that xml to an external web service. I could not find an Salesforce documented way to do so. I do appreciate any hint/sample/idea on that.

closed as off-topic by Martin Lezer, Ratan Paul, Raul, battery.cord, Tushar Sharma Jun 26 '17 at 13:42

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on problems in code you've written must describe the specific problem and include valid code to reproduce it. For help writing short, self-contained syntactically-valid examples, see: SSCCE.org" – Martin Lezer, Ratan Paul, Raul, battery.cord, Tushar Sharma
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    What have you tried so far? Where are you stuck? Please share the code you tried to solve your problem. Please also check out Help Center: How to ask. – Markus Slabina Jun 26 '17 at 9:33

If the volume of data is not huge, then the simplest way to read the data is to use Apex's DOM parser:

Dom.Document doc = new Dom.Document();

and then the various methods that let you walk around the parsed structure.

The same classes work well for when you want to create XML: they handle things like the escaping of characters in strings and allow nested structures to be built up fairly easily. (Building XML by appending strings is pretty fragile.)

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