Tuesday, 28 January 2014

Parsing An XML Data With DOM Parser In Apex

Parsing the XML data in Apex is always pain and there are already very good blogs and links that really help us to design the strategy for parsing XML data of various complexities .

http://www.tgerm.com/2011/01/apex-xmldom-to-fast-xmldom.html

The above blog from Abhinav one of our MVP of sfdc dev commmunity is informational and i suggest everyone to read this on how to use fast XML DOM.

There is a cookbook article as well on how to effectively achieve the parsing of XML using DOM parsers

http://developer.force.com/cookbook/recipe/parsing-xml-using-the-apex-dom-parser

One has to know two system classes a)Document Class b)XMLNode Class
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_xml_dom.htm

Now the question then ,why I am I writing this blog when already there are so much information on web as how to do it.The reason is even after reading all the documents in net ,i struggled to parse an XML as none of the blogs speak on how to parse when we have namespace in the XML.

Here is the sample XML data that i am trying to parse
Now one thing you will observe in the below parser code that i have written ,how i use the namespaces to parse the data.Providing namespace as null will trigger null pointer exceptions

So the idea of this blogpost was just to make one aware on how to parse the XML if there are namespaces .

Hope you enjoyed the blog series .

Introducing Lightning Base Components

Lightning Base Components are great addition to the platform and in fact revolutionary .One of the concerns around lightning component ...