Getting The Attributes Of An Element During XML SAX Parsing

 
 
This Java source code is about Getting the Attributes of an Element During XML SAX Parsing....
 
 
  1. // Create a handler for SAX events

  2.     DefaultHandler handler = new MyHandler();

  3.    

  4.     // Parse an XML file using SAX;

  5. parseXmlFile("infilename.xml",handler,true);

  6.    

  7.     // This class listens for startElement SAX events

  8.     static class MyHandler extends DefaultHandler {

  9.         // This method is called when an element is encountered

  10.         public void startElement(String namespaceURI,String localName,String qName,Attributes atts)  {

  11.             // Get the number of attribute

  12.             int length = atts.getLength();

  13.    

  14.             // Process each attribute

  15.             for (int i=0; i<length; i  ) {

  16.                 // Get names and values for each attribute

  17.                 String name = atts.getQName(i);

  18.                 String value = atts.getValue(i);

  19.    

  20.                 // The following methods are valid only if the parser is namespace-aware

  21.    

  22.                 // The uri of the attribute's namespace

  23.                 String nsUri = atts.getURI(i);

  24.    

  25.                 // This is the name without the prefix

  26.                 String lName = atts.getLocalName(i);

  27.             }

  28.         }

  29.     }

  30.  
 
Copy to Clipboard      Download code as Text Format
 
  Date entered : 5th Apr 2007
  Rating : No Rating
  Accessed  :  5696
  Submitted by :  javabill
 
   Add Comment  Printer friendly
   View All Comments  Email to a friend
   Add to my Favourites Download PDF version
   Rating  
 
                 Click each image to add
this page to each site.
 
 
 
Comments Available

    No comment available at the moment.Be the first one to make a comment

 
Related Java Source Codes
  • Spring
  • Wraps a string to a given number of characters using a string break character
  • Uppercase the first character of each word in a string
  • Make a string's first character uppercase
  • Strip whitespace (or other characters) from the beginning and end of a string

  • Copyright © 2013 VisualBuilder. All rights reserved

    Warning: Unknown(): write failed: Disk quota exceeded (122) in Unknown on line 0

    Warning: Unknown(): Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/tmp) in Unknown on line 0