You need to sign in to do that
Don't have an account?
Dilip_V
XML file Parsing
Hi ,
I have little doubt about XML parsing.
How can we parse an XML file that contains 10 orders and how can we insert them.I tried with DOM class.Using dom I can extract the Information from xml but I am unable to store them into the list of orders with it's childs payments.
Below is my code.
Controller:
Thanks.
I have little doubt about XML parsing.
How can we parse an XML file that contains 10 orders and how can we insert them.I tried with DOM class.Using dom I can extract the Information from xml but I am unable to store them into the list of orders with it's childs payments.
Below is my code.
Controller:
public class ParseTestv1 { // This holds the text we should parse public blob body{get;set;} // This holds the result of any parsing public String parsedText {get; set;} public list<string> ParsedList{get;set;} public String TextToParse {get; set;} // The main method that's called when you click the button public PageReference parse() { parsedlist=new list<string>(); if (body == null) { parsedText = 'Nothing to parse'; } else { TextToParse=body.toString(); parsedText = parse(textToParse); } return null; } // Just checking that it's actually XML private String parse(String toParse) { DOM.Document doc = new DOM.Document(); try { doc.load(toParse); DOM.XMLNode root = doc.getRootElement(); return walkThrough(root); } catch (System.XMLException e) { // invalid XML return e.getMessage(); } } // Recursively walk through the XML private String walkThrough(DOM.XMLNode node) { String result = '\n'; if (node.getNodeType() == DOM.XMLNodeType.COMMENT) { return 'Comment (' + node.getText() + ')'; } if (node.getNodeType() == DOM.XMLNodeType.TEXT) { return 'Text (' + node.getText() + ')'; } if (node.getNodeType() == DOM.XMLNodeType.ELEMENT) { result += + node.getName(); if (node.getText().trim() != '') { result += '=' + node.getText().trim(); } if (node.getAttributeCount() > 0) { for (Integer i = 0; i< node.getAttributeCount(); i++ ) { result += ', attribute #' + i + ':' + node.getAttributeKeyAt(i) + '=' + node.getAttributeValue(node.getAttributeKeyAt(i), node.getAttributeKeyNsAt(i)); } } for (Dom.XMLNode child: node.getChildElements()) { result += walkThrough(child); } return result; } return ''; //should never reach here } }Page:
<apex:page controller="ParseTestv1" sidebar="false" showHeader="false" > <apex:form > <apex:inputFile value="{!body}" /> <apex:inputtextarea cols="40" rows="20" id="result" value="{!parsedText}"/> <br/> <apex:commandButton value="Parse" action="{!parse}"/> </apex:form> </apex:page>
Thanks.
All Answers
[1] https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_xml_dom.htm
is it possible to extract and process data of 32 mb xml file using apex(using above apex class).??
If not how to do it.
Thanks
32 mb data is located in box or some other sites.So Can we use batch class for that?
Is there any chance to get out of the limits for processing that file?