0
DOM.Document xmlDOC = new DOM.Document();
xmlDOC.load(xmlstring); 
DOM.XMLNode rootElement = xmlDOC.getRootElement();
for(DOM.XMLNode xmlnodeobj:xmlDOC.getRootElement().getChildElements()){
    For(Quote_line_item__c q:q1){   
        if(q.Name==xmlnodeobj.getChildElement('REF',null).getText()){
            q.Current_Stock__c= xmlnodeobj.getChildElement('QUANTITY',null).getText();
        }
    }
}

Sample XML string:

XMLString='<RESULT><LINE><REF>12600</REF><QUANTITY>980</QUANTITY></LINE><LINE><REF>12601</REF><QUANTITY>3254</QUANTITY></LINE></RESULT>';

Exception : Visualforce Error Help for this Page

System.NullPointerException: Attempt to de-reference a null object Class.createorder.: line 128, column 1 xmlnodeobj.getChildElement('REF',null).getText()

Null pointer exception coming from this statement.

Can any body help me regarding this?

1

In the code you should check for NULL condition as:

   DOM.Document xmlDOC = new DOM.Document(); 
   xmlDOC.load(xmlstring); 
   DOM.XMLNode rootElement = xmlDOC.getRootElement();
   for(DOM.XMLNode xmlnodeobj:xmlDOC.getRootElement().getChildElements()){
    if(xmlnodeobj.getChildElement('REF',null) != null) // CHECK FOR NULL
      for(Quote_line_item__c q:q1){   
        if(q.Name==xmlnodeobj.getChildElement('REF',null).getText()){
          q.Current_Stock__c=     xmlnodeobj.getChildElement('QUANTITY',null).getText();

      }
    }
   }       

it seems like you are skipping <LINE> and trying to parse directly REF.

  • i am passing 4 set i am getting result for only first set q.Current_Stock__c – Karthika Ram Jan 12 '16 at 10:14
  • Can you post the updated code? @KarthikaRam – Ashwani Jan 12 '16 at 10:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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