+ Start a Discussion
SF Beginner 2019SF Beginner 2019 

Parsing XML in a stored field and store on a new custom Object

I have this Custom Object Named Stored XML.

and one of the field stores an XML strings.

<?xml version="1.0" encoding="UTF-8"?><consumers xmlns="http://test.com/feed/">
<SupplyResult>
 <MarketId>xxxxxxxx</MarketId>
 <SupplyList>
    <member>
        <Quantity>9</Quantity>
        <InStock>5</InStock>
        <SellerSKU>Test- 1111</SellerSKU>
    </member>
  </SupplyList>
  </SupplyResult>


How do I parse this and store all the field on on a new Custom Object Named XML Parsed?

Thank you!
Khan AnasKhan Anas (Salesforce Developers) 
Hi,

Greetings to you!

You can use the Dom.Document class. Apex provides classes that enable you to work with XML content using the DOM (Document Object Model).
DOM classes help you parse or generate XML content. You can use these classes to work with any XML content. One common application is to use the classes to generate the body of a request created by HttpRequest or to parse a response accessed by HttpResponse. The DOM represents an XML document as a hierarchy of nodes. Some nodes may be branch nodes and have child nodes, while others are leaf nodes with no children. You can parse nested XML content that’s up to 50 nodes deep.

Please refer to the below links which might help you further with the above requirement.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_xml_dom.htm

https://developer.salesforce.com/forums/?id=906F00000008zJNIAY

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
SF Beginner 2019SF Beginner 2019
Hi

Thank you,

but it seems what I need is that every record contains a string like this but different values..

<?xml version="1.0" encoding="UTF-8"?><consumers xmlns="http://test.com/feed/">
<SupplyResult>
 <MarketId>xxxxxxxx</MarketId>
 <SupplyList>
    <member>
        <Quantity>9</Quantity>
        <InStock>5</InStock>
        <SellerSKU>Test- 1111</SellerSKU>
    </member>
  </SupplyList>
  </SupplyResult>

So how can I parse each record on that object and store them on a custom object.

Thank you!