Optimizing XMLparsing with code generation
I was looking at some parsers using SAX recently, and was struck by the huge chains of if/elseif/else within the startElement and endElement callbacks. For example:
public void startElement(String uri, String
Tutorial Details:
Unfortunately, Xerces does not support this feature! /img/emoticons/sad.gif For my personal projects I try to use gnujaxp, which does, but applications that need to work with an arbitrary SAX parser cannot rely on interning.
But even with lame parsers we can now use the string-switching capabilities of CGLIB to gain back most of the speed of interning. I have checked net.sf.cglib.util.StringSwitcher into CVS. The API is very simple:
private static final int FOO = 0, BAR = 1, BAZ = 2;
private static final StringSwitcher SWITCHER =
StringSwitcher.create(new String[]{ \"foo\", \"bar\", \"baz\" },
new int[]{ FOO, BAR, BAZ },
true);
Of course the string and integer arrays can be as long as you want (it would not be worth it for only three). The third parameter is a boolean that indicates whether the switcher will only be called with strings from the argument array. For validated documents this is safe and gives a 3X speedup.
Read
Tutorial at: Click here to view the tutorial
Rate Tutorial: Optimizing XML
parsing with code generation
View Tutorial: Optimizing XML
parsing with code generation
Related
Tutorials:
Programming XML in Java, Part 1 - JavaWorld March 2000
Programming XML in Java, Part 1 - JavaWorld March 2000 |
Code generation using Javadoc - JavaWorld August
2000
Code generation using Javadoc - JavaWorld August
2000 |
Mapping XML to Java, Part 1 - JavaWorld August 2000
Mapping XML to Java, Part 1 - JavaWorld August 2000 |
Validation with Java and XML Schema, Part 2 - JavaWorld October 2000
Validation with Java and XML Schema, Part 2 - JavaWorld October 2000 |
Solve your
servlet-based presentation problems - JavaWorld November
2000
Solve your
servlet-based presentation problems - JavaWorld November
2000 |
Validation with Java and XML schema, Part 3 - JavaWorld November 2000
Validation with Java and XML schema, Part 3 - JavaWorld November 2000 |
Eliminate tedious programming: Recover data with XML and Reflection - JavaWorld November
2000
Eliminate tedious programming: Recover data with XML and Reflection - JavaWorld November
2000 |
Build your own
languages with
JavaCC - JavaWorld December
2000
Build your own
languages with
JavaCC - JavaWorld December
2000 |
Jato: The new kid on the open source block - JavaWorld March 2001
Jato: The new kid on the open source block - JavaWorld March 2001 |
The magic of Merlin - JavaWorld March 2001
The magic of Merlin - JavaWorld March 2001 |
Breathe intelligence into Java - JavaWorld April 2001
Breathe intelligence into Java - JavaWorld April 2001 |
Use XML data binding to do your
laundry
Use XML data binding to do your
laundry |
Axis: The next generation of Apache SOAP
Axis: The next generation of Apache SOAP |
Take the sting out of SAX
Take the sting out of SAX |
FastParser 1.6.3
FastParser 1.6.9.1
XML Edition
FastParser is a Java Xml parser
High performance XML parser (benchmarks* : up to +100% faster compared to Xerces and JDK1.4 integrated parser)
SAX Level 1 and 2 compliant
DOM support
JAXP compatibility
Names |
Template-Based Code Generation with Apache Velocity, Part 1
Template-Based Code Generation with Apache Velocity, Part
I'm going to discuss template-based code generation, explain basic concepts related to templates and transformations, and demonstrate the huge benefits they can bring in code generation. |
Extensible Code Generation with Java, Part 1
Extensible Code Generation with Java, Part 1
Code generation is a key new trend in engineering, one that you need to understand well. The reason is simple: today's modern frameworks are extremely code-intensive. Using a code generator to build the code |
Parsing and Processing Large XML Documents with Digester Rules
Parsing and Processing Large XML Documents with Digester Rules
XML is commonly used for integration with third-party applications or web services, especially those that are running on non-Java platforms. On the other hand, if the code is running in a man |
Parsing an XML Document with XPath
The getter methods in the org.w3c.dom package API are commonly used to parse an XML document. But J2SE 5.0 also provides the javax.xml.xpath package to parse an XML document with the XML Path Language (XPath) .
|
DB Visual Architect for Eclipse
DB Visual Architect for Eclipse (DBVA-EC) is a full featured Object Relational Mapping (ORM) plugin for Eclipse that provides the industry\'s best round-trip code engineering support with Java. |
|
|
|