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 Answer 1

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.

2
  • i am passing 4 set i am getting result for only first set q.Current_Stock__c Commented Jan 12, 2016 at 10:14
  • Can you post the updated code? @KarthikaRam Commented Jan 12, 2016 at 10:23

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.