I wrote a class which given below.

public class DomDocument {

    Public void parseXmlFile(String xml){

        Dom.Document doc=new Dom.Document();
        Dom.XmlNode node= doc.getRootElement();
        String name= node.getChildElement('Name',null).getText(); // Error is coming here
        String country= node.getChildElement('country',null).getText();


Actually, i want to work with below xml

    <name>Kirk Stevens</name>
    <street1>808 State St</street1>
    <street2>Apt. 2</street2>

I am trying to execute this class by using execute anonymous. I am getting NullPointer Exception while i have used the above xml file as a string in parseXmlFile(String xml) like below

parseXmlFile('<address><name>Kirk Stevens</name><street1>808 State St</street1><street2>Apt. 2</street2><city>Palookaville</city><state>PA</state><country>USA</country></address>');

could anyone help me out in this. Thanks


Try with below code, issue might be with case sensitivity.

String name= node.getChildElement('name',null).getText();
| improve this answer | |

Your Answer

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