function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ashmi PatelAshmi Patel 

Read only property 'ParseTest.parsedText'

this is class code:::

public class ParseTest{

    public String getParsedText() {
        return null;
    }


    public String textToParse { get; set; }
    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 += 'Element: ' + node.getName();
    if (node.getText().trim() != '') {
      result += ', text=' + 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
}
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();
  }
}
}

this is apex page::

<apex:page controller="ParseTest" sidebar="false" showHeader="false" > <apex:form> <apex:inputtextarea cols="40" rows="20" value="{!textToParse}" /> <apex:inputtextarea cols="40" rows="20" id="result" value="{!parsedText}"/> <br /> <apex:commandButton value="Parse" action="{!parse}" reRender="result"/> </apex:form> </apex:page>

 
FearNoneFearNone
Hi Ashmi Patel,

As what as error says, the apex page tries to write to "parsedText", but it can not because it is just a read-only property.
therefore, you have to add a setter property for "parsedText".
how about changing your code from:
public String getParsedText() {
    return null;
}

to:
public String parsedText {
   get { return parsedText; }
   set { parsedText = value; }
}


Good Luck!