advertisement
Premier Club Log In/Registration
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   SKILLBUILDING  |   TIP BANK  |   SOURCEBANK  |   FORUMS  |   NEWSLETTERS
Browse DevX
Partners & Affiliates
advertisement
advertisement
Tip of the Day
Rate this item | 0 users have rated this item.
Expertise: Intermediate
Language: Java
March 2, 2006
How Powerful Is Your StAX Parser?
This tip is a simple application that demonstrates the possibilities of your StAX parser by setting the XMLInputFactory properties to true/false. The StAX parser tested in this example is the BEA and JCP parser.

import javax.xml.stream.*;

public class XMLInputFactoryProperties{
 
    public static void main(String[] args)
        {
        String[] properties={"javax.xml.stream.isValidating",
                   "javax.xml.stream.isNamespaceAware",
                   "javax.xml.stream.isCoalescing","javax.xml.stream.isReplacingEntityReferences",
                   "javax.xml.stream.isSupportingExternalEntities","javax.xml.stream.supportDTD"};
        XMLInputFactory XMLif=null;
              
        System.setProperty("javax.xml.stream.XMLInputFactory","com.bea.xml.stream.MXParserFactory");

        //get an XMLInputFactory instance
        XMLif=XMLInputFactory.newInstance();
                
        //testing
        System.out.println("Case 1:");
        for(int i=0;i<properties.length;i++)
             { 
             try{            
                XMLif.setProperty(properties[i],Boolean.TRUE);   
                System.out.println("---OK-"+properties[i]+"-OK---\n");
                }catch(java.lang.IllegalArgumentException e)
                   {
                   System.out.println("---NO-"+properties[i]+"-NO---");
                   System.out.println(e.getMessage()+"\n");                   
               }
            }

        System.out.println("Case 2:");
        for(int i=0;i<properties.length;i++)
             { 
             try{            
                XMLif.setProperty(properties[i],Boolean.FALSE);   
                System.out.println("---OK-"+properties[i]+"-OK---\n");
                }catch(java.lang.IllegalArgumentException e)
                   {
                   System.out.println("---NO-"+properties[i]+"-NO---");
                   System.out.println(e.getMessage()+"\n");                   
               }
            }
             
        }   
     }      
Anghel Leonard
If you have a hot tip and we publish it, we'll pay you. However, due to accounting overhead we no longer pay $10 for a single tip submission. You must accumulate 10 acceptable tips to receive payment. Be sure to include a clear explanation of what the technique does and why it's useful. If it includes code, limit it to 20 lines if possible. Submit your tip here.
Please rate this item (5=best)
 1  2  3  4  5
advertisement
advertisement
Advertising Info  |   Member Services  |   Permissions  |   Help  |   Site Map  |   Network Map  |   About


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers