• Like
JSR 172: XML Parsing in MIDP
Upcoming SlideShare
Loading in...5
×

JSR 172: XML Parsing in MIDP

  • 2,766 views
Uploaded on

 

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
2,766
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
53
Comments
0
Likes
2

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. JAXP Parsing in Java ME
  • 2. JSR 172
    • JSR 172: Java ME Web Services
      • Access to remote SOAP / XML Based web services
      • Parsing XML data
  • 3. JAXP Java ME Edition
    • JSR 172 is a subset of JSR 063
      • JSR 63: Java API for XML Processing
      • http://jcp.org/en/jsr/detail?id=63
    • Requires only CLDC 1.0
    • Basic XML Parsing capabilities
  • 4. API Features and Restrictions
    • SAX 2.0 subset
    • XML Namespaces
    • UTF-8 and UTF-16 support
    • May support validation (DTD)
    • No DOM – handling
      • Too heavy, size and runtime memory
    • No XSLT Transformations
  • 5. Packages
    • javax.xml.parsers
      • To obtain and reference platform's parser
        • SAXParser, SAXParserFactory...
    • org.xml.sax
      • Subset of SAX 2.0 API Classes and interfaces.
        • Attributes, Locator, InputSource, SAX??Exceptions
    • org.xml.sax.helpers
      • Class to extend to receive parse events
        • DefaultHandler
  • 6. Basic Idea behind SAX
    • SAX = Simple API for XML
      • See http://en.wikipedia.org/wiki/Simple_API_for_XML
    • Event driven way of handling xml-data
    • Only reading (no manipulation of the xml – data)
  • 7. Creating Parser
    • SAXParserFactory factory = SAXParserFactory.newInstance();
    • SAXParser saxParser = factory.newSAXParser();
    • saxParser. parse (..., ...);
  • 8. SAXParser parse
    • parse(org.xml.sax.InputSource is, DefaultHandler dh);
    • parse(java.io.InputStream is, DefaultHandler dh);
  • 9. Default Handler?
    • Create your own handler by inheriting the Default Handler
      • Class MyHandler extends DefaultHandler {
      • }
    • Override methods you want
  • 10. Example
    • public class MyXMLParser extends DefaultHandler {
    • public void startDocument () throws SAXException { }
    • public void startElement (String uri, String localName, String qName, Attributes attributes) throws SAXException { }
    • public void characters (char[] ch, int start, int length) throws SAXException { }
    • public void endElement (String uri, String localName, String qName) throws SAXException { }
    • public void endDocument () throws SAXException { }
    • }
  • 11. Creating Parser
    • SAXParserFactory factory = SAXParserFactory.newInstance();
    • SAXParser saxParser = factory.newSAXParser();
    • String xml = &quot;<root><child>content</child></root>&quot;;
    • ByteArrayInputStream s = new ByteArrayInputStream(xml.getBytes());
    • saxParser. parse (s, new MyXMLParser());