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 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(); doc.load(xml);
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.)