1

I am having the following XML:

<Fields><orderTAb.SapService>Bhagya/Comp/Comp_Total##FALSE$$FR2:LB9000400008##FR098990</orderTAb.SapService>
</Fields>

I tried:

    //Parsing the OrderInfoTab.dataServicePage field
                 if (xsr.getEventType() == XmlTag.START_ELEMENT && xsr.getLocalName() == 'orderTAb.SapService'){
                     xsr.next();
                     if(xsr.hasText()){
                         string dataService = xsr.getText();
                          if(dataService.indexOf('Bhagya/Comp/Comp_Total') != -1){
                             ServiceCalculationsettingsH = 'Total';
                         }

    //Reading
    if(reader.getEventType() == XmlTag.START_ELEMENT && reader.getLocalName() == 'orderTAb.SapService'){
            reader.next();
            if(reader.hasText()){

            if (reader.getText() == 'Bhagya/Comp/Comp_Total')
            {
            values[10] = '"'+reader.getText()+'"';
            QC.ServiceCal = '"'+reader.getText()+'"';
            System.debug('QC.ServiceCal1--------------------'+QC.ServiceCal);
                }
                 if (reader.getEventType() == XmlTag.END_ELEMENT && reader.getLocalName() =='orderTAb.SapService') {
                temp += string.join(values,',') + '\n';
                lstQuoteContent.add(QC);
                System.debug('CHP-50:   ' +lstQuoteContent );
                break;
            }
            reader.next();

//To display Node(Tag)
if(lstquotecontent.size() > 0){
            for(Integer i = 0 ; i < lstquotecontent.size() ; i++){
             if(lstquotecontent[i].ServiceCal != NULL)
                    quotecontentLineItem.addChildElement('ServiceCal', null, null).addTextNode(lstquotecontent[i].ServiceCal);
                 else
                    quotecontentLineItem.addChildElement('ServiceCal', null, null).addTextNode('');
                }

Node get display properly in XML response but showing null value.

  • //Parsing the OrderInfoTab.dataServicePage field if (xsr.getEventType() == XmlTag.START_ELEMENT && xsr.getLocalName() == 'orderTAb.SapService'){ xsr.next(); if(xsr.hasText()){ string dataService = xsr.getText(); if(dataService.indexOf('Bhagya/Comp/Comp_Total') != -1){ ServiceCalculationsettingsH = 'Total'; } – Bhagyashree Shinde Oct 26 '18 at 10:10
  • edit your question with code please – Oleksandr Berehovskyi Oct 26 '18 at 10:11
  • and last part. What problem do you have? Any error message ? – Oleksandr Berehovskyi Oct 26 '18 at 10:16
  • The problem I craeted one node with name ServiceCal in that ,I want to fetch this value "Bhagya/Comp/Comp_Total##FALSE$$FR2:LB9000400008##FR098990". It showing null. – Bhagyashree Shinde Oct 26 '18 at 10:34
2

Use the Apex DOM parser - it is way easier to get the code right:

String xml = '<Fields><orderTAb.SapService>Bhagya/Comp/Comp_Total##FALSE$$FR2:LB9000400008##FR098990</orderTAb.SapService></Fields>';
Dom.Document doc = new Dom.Document();
doc.load(xml);
System.debug(doc.getRootElement().getChildElement('orderTAb.SapService', null).getText());
  • Requirement is only fetch a value which come into < ordertab.service> for response xml – Bhagyashree Shinde Oct 26 '18 at 14:27
  • 1
    @BhagyashreeShinde That is what the code I posted does: it picks out that value. Run it and see. – Keith C Oct 26 '18 at 14:45

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.