P
pp
I would like to process an XML document with a Java application,
utilizing the Apache Xerces SAX2 parser.
Based on the name of an element and the value of its specific
attributes, I would like to perform some processing on the data that
this element encloses. Suppose, for example, an element in the XML
document looks like
<my_element name="el" number="1"> element data </my_element>
then I need to protocol the content of the 'name' attribute and based
on its value, I need to process the 'element data' contents. What
disturbs me is that I cannot make all the processing at once and should
wait for the specific parser callbacks to provide the needed
information. E.g. I obtain the 'name' attribute value in the
startElement callback and the 'element data' in the characters callback
of the SAX ContentHandler interface.
Is there a finer way to do the processing in a single method, instead
of using global variables that should be changed by the respective
callback method? I cannot rely on some return parameters for the SAX
callbacks, because their return type is void.
I do not want to have a random access over the whole information in the
XML document. It is about having the value of the 'name' attribute and
the 'element data' of a single 'my_element' at the same time. Any ideas
how to make that happen please?
utilizing the Apache Xerces SAX2 parser.
Based on the name of an element and the value of its specific
attributes, I would like to perform some processing on the data that
this element encloses. Suppose, for example, an element in the XML
document looks like
<my_element name="el" number="1"> element data </my_element>
then I need to protocol the content of the 'name' attribute and based
on its value, I need to process the 'element data' contents. What
disturbs me is that I cannot make all the processing at once and should
wait for the specific parser callbacks to provide the needed
information. E.g. I obtain the 'name' attribute value in the
startElement callback and the 'element data' in the characters callback
of the SAX ContentHandler interface.
Is there a finer way to do the processing in a single method, instead
of using global variables that should be changed by the respective
callback method? I cannot rely on some return parameters for the SAX
callbacks, because their return type is void.
I do not want to have a random access over the whole information in the
XML document. It is about having the value of the 'name' attribute and
the 'element data' of a single 'my_element' at the same time. Any ideas
how to make that happen please?