3. Developers not aware of
recent platform changes.
Google gives pointers to
obsolete APIs.
Obsolete APIs are slow and
hurt on governor limits like
Motivation “script statements
consumption”
New APIs use platform
capabilities for resource
hungry tasks like parsing.
Why we are discussing this ?
4. Native Lib ?
Provided by Force.com
platform aka System libraries,
like XMLStreamReader
Doesn’t hurt on resources like
Native Lib script statements
consumption.
vs
Apex Lib Apex Lib ?
Wrapper on Native Lib, like
XMLDOM.cls
Written from scratch in Apex
only, like JSONObject.cls
7. public class Book {
String name;
String author;
}
Apex Model
Parse XML to this Model
8. XMLStream Classes
Native Lib
Stream based approach to
parse XML
Classic XMLDom.cls (OpenSource)
Approaches Apex Lib, wrapper on above
XMLStream classes
Create in memory DOM for
XML Structure.
Written by Ron Hess
(Salesforce)
9. Dom.Document/XmlNode
Classes
Native Lib
Came in Spring’10 release
DOM based approach to parse
XML
Better
Approaches FastXmlDom (OpenSource)
Apex Lib, wrapper on above
Dom.XmlNode classes
Exposes pretty common DOM
API for XML Parsing
Tested & used in many
projects.
10. Over to sublime code snippet
Sample Code
Lets see some code about all of
these approaches
11. Pros
Native Lib (Not an Apex
implementation)
Heap/Memory efficient like
usual stream parsers.
XmlStream Good for big XML string, parse
only the required part of XML.
Classes Cons
Complex code to parse XML.
Not so developer friendly
Sometimes can consume lots
of script statements in
Pros/Cons iterations for big XMLs.
12. Pros
Simple W3C DOM library,
which developers are used to
of using in HTML DOM as well.
Simple and more readable
code for XML Parsing.
Cons
XMLDOM.cls Creates in memory DOM for
complete XML structure, so
heavy on heap
Consumes too many script
statements in the above
process.
Not suitable for large XML
parsing.
13. Pros
Native DOM Lib
Relatively simpler to use as
compared to
XMLStreamReader.
Dom class Consumes least script
Document & statements.
Cons
XmlNode
DOM API is not following w3c
model, so learning curve for
developers.
Mandates namespace
usage, that complicates simple
xml parsing.
14. Pros
Exposes W3C DOM API (no
learning curve for developers)
Simpler to use as compared to
XMLStreamReader and DOM
Classes.
FastXMLDom Consumes less script
statements.
Cons
An Apex Lib, so consumes a bit
more script statements and
heap as compared to
Dom.XmlNode
Pros/Cons
16. JSONObject.cls
Apex Lib
Tokenizes the string to create
in memory JSON Structure
Written by Ron
Classic Hess(Salesforce)
System.JSONParser
Approaches
Native lib
Streaming and token based
parsing of JSON
17. JSON
Native Lib
Mapped strong and loose
parsing with Apex UDT(User
Defined Types) and
Collections like Maps.
Better
Approaches
18. JSONObject
Not required and please don’t
use it any more.
JSONParser
http://www.salesforce.com/us/
developer/docs/apexcode/Con
Sample Code tent/apex_methods_system_js
onparser.htm
JSON
http://www.tgerm.com/2011/10
/winter12-jsonparser-
serialize.html
19. Pros
None as of now
Cons
Consumes script statements
JSONObject.cls and heap for large JSON files
Not as stable as compared to
Native libs.
20. Pros
Native lib, hurts less on
resources.
Good option when JSON
automated
serialization/deserialization
fails.
JSONParser Came with Winter’12 release
Cons
Complex code and less
developer friendly way to
parse.
21. Pros
Native lib, hurts less on
resources.
Serialize/De-serialize big
JSON strings in one line of
code.
Easy transformation of JSON
from String > UDT and vice
versa
JSON Gives option of loose parsing
to Maps i.e.
deserializeUntyped()
Came with winter’12 release
Improved a bit with every next
release
Cons
Special care if required if
JSON contains reserved words
or conflicting stuff with Apex.
22. Searching for solutions in this
order
Consult platform guides, like
apex dev guide.
developer.force.com
Salesforce.stackexchange.com
Google
General Tips Stay on latest and greatest
API
Don’t download pdf for
documentation use online
guides.
Use latest API version of Apex
class and VF page when
creating new ones.
24. Use “Apex Developer Guide” for
native libs, like:
XmlStreamReader
Dom classes
JSON Parser
JSON
XMLDOM.cls
http://developer.force.com/projectpa
ge?id=a0630000002ahp5AAA
Resources Fast XML DOM
http://code.google.com/p/apex-fast-
xml-dom/
JSONObject.cls
http://code.google.com/p/apex-
You will get all the link, as I will library/source/browse/trunk/JSONO
share the slides bject/src/classes/JSONObject.cls
Your introductory or title slide should convey the overall “feeling” and focus of your presentation. For instance, I typically present about small-business trends, new business ideas, growth opportunities or other positive trends. In this sample presentation, I’m talking about new business ideas, so I used a sun graphic in this slide template to convey a positive feeling. Personalize this slide template with your company’s logo. To add a logo to all slides, place it on the Slide Master. To access the Slide Master, on the Themes tab of the Ribbon, click Edit Master and then click Slide Master.Disclaimer: You understand that Microsoft does not endorse or control the content provided in the following presentation. Microsoft provides this content to you for informational purposes only; it is not intended to be relied upon as business or financial advice. Microsoft does not guarantee or otherwise warrant the accuracy or validity of this information and encourages you to consult with a business or financial professional as appropriate.RIEVA LESONSKY Founder and President, GrowBiz Media RievaLesonsky is founder and president of GrowBiz Media, a content and consulting company specializing in covering small businesses and entrepreneurship. A nationally known speaker and authority on entrepreneurship, Lesonsky has been covering America’s entrepreneurs for nearly 30 years. Before co-founding GrowBiz Media, Lesonsky was Editorial Director of Entrepreneur Magazine.