Jakiro Dragon Jakiro Dragon - 1 year ago 54
Java Question

XML getting value from specific duplicate tag using sax parser java

im trying to getting some information in my xml using sax parser,

here it is :

<IDENT>show</IDENT>
<FORMAL_PARAM_LIST>
FORMAL_PARAM_LIST
</FORMAL_PARAM_LIST>
<BLOCK_SCOPE>
BLOCK_SCOPE
<VAR_DECLARATION>
VAR_DECLARATION
<LOCAL_MODIFIER_LIST>
LOCAL_MODIFIER_LIST
</LOCAL_MODIFIER_LIST>
<TYPE>
TYPE
<QUALIFIED_TYPE_IDENT>
QUALIFIED_TYPE_IDENT
<IDENT>MenuUI</IDENT>
</QUALIFIED_TYPE_IDENT>
</TYPE>
<VAR_DECLARATOR_LIST>
VAR_DECLARATOR_LIST
<VAR_DECLARATOR>
VAR_DECLARATOR
<IDENT>menu</IDENT>
<EXPR>
EXPR
<CLASS_CONSTRUCTOR_CALL>
STATIC_ARRAY_CREATOR
<QUALIFIED_TYPE_IDENT>
QUALIFIED_TYPE_IDENT
<IDENT>MenuUI</IDENT>
</QUALIFIED_TYPE_IDENT>
<ARGUMENT_LIST>
ARGUMENT_LIST
</ARGUMENT_LIST>
</CLASS_CONSTRUCTOR_CALL>
</EXPR>
</VAR_DECLARATOR>
</VAR_DECLARATOR_LIST>
</VAR_DECLARATION>
<EXPR>
EXPR
<METHOD_CALL>
METHOD_CALL
<DOT>.<IDENT>menu</IDENT><IDENT>showJASPform</IDENT></DOT>
<ARGUMENT_LIST>
ARGUMENT_LIST
</ARGUMENT_LIST>
</METHOD_CALL>
</EXPR>
</BLOCK_SCOPE>


basicly i want to take ident tag (), in the xml theres 4 ident, but the problem is i dont want to take them all, i only want to take the first ident (show ident) i already trying to figure it out by implementing boolean value to flag my current position in xml's element, but i confused how i can stop at the first ident.

thank you very much for ur attention

Answer Source

Use class derived from org.xml.sax.helpers.DefaultHandler. Throw SAXException as soon as you will find desired element in startElement() method. This will stop SAX parser immediately.

Here are example provided - Stop a SAX parser when you have enough data

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download