XML parsing in Blackberry
The Simple API for XML (SAX) was developed by members of the public mailing list (XML-DEV). It provides an event-based approach to XML parsing. This means that instead of moving from node to node, it goes from event to event. SAX is an event driven interface. Events include an XML tag, error detection, etc. J2ME SAX - see BlackBerry / J2ME - SAX parsing a collection of objects with attributes
XML parser - it is optimal for applications that require a fast and small XML parser. It should be used when the whole process needs to be executed quickly and efficiently for inputting kXML elements - J2ME pull parser - see Best approach for creating XML in Blackberry
XML parsing with JSON
Blackberry standard for parsing JSON JSON ME
I donโt know ... JSON can be represented and ported as XML, but not vice versa.
XML (Extensible Markup Language) is a set of rules for encoding documents electronically. It is defined in the XML 1.0 Specification, created by W3C, and several other related specifications, all free open standards.
XML example:
<?xml version="1.0" encoding='UTF-8'?> <painting> <img src="madonna.jpg" alt='Foligno Madonna, by Raphael'/> <caption>This is Raphael "Foligno" Madonna, painted in <date>1511</date>โ<date>1512</date>. </caption> </painting>
JSON (an abbreviation for JavaScript Object Notation) is a lightweight text-based open standard for exchanging data with a person. It is derived from the JavaScript programming language for representing simple data structures and associative arrays called objects ("O" in "JSON"). Despite its connection with JavaScript, it is language independent, and parsers are available for almost any programming language.
JSON example:
{ "firstName": "John", "lastName": "Smith", "age": 25, "address": { "streetAddress": "21 2nd Street", "city": "New York", "state": "NY", "postalCode": "10021" }, "phoneNumber": [ { "type": "home", "number": "212 555-1234" }, { "type": "fax", "number": "646 555-4567" } ] }
Basically, if your XML is a strong JSON equivalent, for example:
<Person> <firstName>John</firstName> <lastName>Smith</lastName> <age>25</age> <address> <streetAddress>21 2nd Street</streetAddress> <city>New York</city> <state>NY</state> <postalCode>10021</postalCode> </address> <phoneNumber type="home">212 555-1234</phoneNumber> <phoneNumber type="fax">646 555-4567</phoneNumber> </Person>
It is possible to parse such XML using JSON.