Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Compiling XPaths

HC kicks off with a first implementation of DFA construction

Return to article.


Listing 4: DFAHandler.java
protected static class DFAHandler
   extends DefaultHandler
{
   protected DFATable table;
   protected int state;
   protected Stack stack;

   public DFAHandler(DFATable table)
   {
      this.table = table;
   }

   public void startDocument()
   {
      state = -1;
      stack = new Stack();
   }

   public void startElement(String namespaceURI,
                            String localName,
                            String qualifiedName,
                            Attributes atts)
   {
      stack.push(new Integer(state));
      QName qname = new QName(QName.ELEMENT,
		                        namespaceURI,
										localName);
      state = table.move(qname,state);
      System.out.println(qname.toString() + 
		                   " caused a transition to " + 
								 state);
      if(table.isAcceptingState(state))
         System.out.println("found " +
			                   table.getAssociatedData(state));
   }

   public void endElement(String namespaceURI,
                          String localName,
                          String qualifiedName)
   {
      state = ((Integer)stack.pop()).intValue();
   }
}

<db:sect1 xmlns:db="http://www.ananas.org/2001/docbook">
   <db:sect1info/>
   <db:simpara/>
   <db:simpara><db:ulink/></db:simpara>
</db:sect1>

Return to article.