XMLReader xmlReader = null;
try
{
SAXParserFactory spfactory =
SAXParserFactory.newInstance();
spfactory.setValidating(false);
SAXParser saxParser = spfactory.newSAXParser();
xmlReader = saxParser.getXMLReader();
try
{
xmlReader.setFeature( "http://xml.org/sax/features/namespaces",
true);
}
catch
(SAXException e) {
System.err.println("could
not set parser
feature");
}
SurveyReader t =
new
SurveyReader();
xmlReader.setContentHandler(t);
xmlReader.setErrorHandler(t);
InputSource source = new
InputSource(xmlSource);
xmlReader.parse(source);
I am creating and populating Vectors in startElement, characters and
endElement methods. if I print contents of those vectors just after xmlReader.parse(source)
line, it correctly displays the contents of Vectors. That proves the
XML is correctly parsed.
But what I am doing is, instantiating the class containing this code inside
a method of another class. On that instance, I invoke the method containing
above mentioned code. After calling that method(The Vectors should have been
filled now), I get the Vectors on that instance. eg. ins.VectName;. But at this point the Vectors are empty and
not filled with contents of XML.
That's the problem I am facing. I appreciate any help.
Thanks and best regards
Ranjith
----- Original Message -----
Sent: Thursday, November 04, 2004 9:52
PM
Subject: Re: Problem with SAX Parsing in
Xerces
Which parser are you using?
and at what point of your code are you calling the parse method?
SAX uses the observer/observable design
pattern and your handler (DefaultHandler in your case) is the observer and the
parser (use XMLReader) is the observable.
XMLReader should open the URL (or the input stream) and starts parsing
the XML and it notifies the observer (handler) when it starts an element, end
an element, etc...
I think that's
your problem, you are not parsing the XML. So write another class that gets an
instance of the XMLReader (use the XMLReaderFactory.createXMLReader()) and
then install the handler on it and then call it's parse method.
Hope that helps.
-ramin
| "Ranjith Kodikara"
<[EMAIL PROTECTED]>
11/04/2004 12:54 AM
|
Please respond
to [EMAIL PROTECTED] |
|
|
To
| [EMAIL PROTECTED]
|
|
cc
|
|
|
Subject
| Problem with SAX
Parsing in Xerces |
|
Hi,
My XML parsing program contains two java classes. The SurveyReader.java
extends DefaultHandler interface and contains startElement, endElement and
characters methods. It has 5 Vector member variables defined.
In startElement method I create a new Hashtable.
In characteres method I populate that hashtable
with put method.
In endElement method, I
add the Hashtable to the Vector member variable.
My other java class
PopWOTC.java extends VBean class, because I have developed that to embed in
Oracle form and to put it to Oracle 9iAs.
In that class's popQuotation method, I instantiate the above mentioned
SurveyReader class and execute the doTheWork method. ( The http url is
accessed and there is no problem with it, because I have updated the
java.policy file in the Oracle jinitiator.)
SurveyReader r = new SurveyReader();
r.doTheWork("http://ranjith:8080/itos/tour1.jsp?progyear="+progYr+"&progno="+progNo+"&tourseq="+tourSeq+"&sessionid="+sessionid+"");
System.out.println(r.evtdVect.toString() ) ===> returns []
evtdVect is the Vector Defined in SurveyReader class.
When
doTheWork() method is executed, the Vector should have been filled with
hashtables. But just after doTheWork method, I call r.evtdVect (The Vector
defined in SurveyReader.java class), but its not been filled. At this
moment I see that the startElement, characters and endElement methods are not
finished executing. Actually I need to access the SurveyReader's Vector member
variable from PopWOTC class after calling dotheWork method.
I think something wrong here
with SAX; Xerces.
I attach the SurveyReader class herewith. I would be greatful for any
help.
Thanks
and best regards,
Ranjith
[EMAIL PROTECTED]
|
|
Ranjith
Kodikara Systems Engineer
|
DMS
Software Technologies 165, Dharmapala Mawatha, Colombo
00700
|
| [EMAIL PROTECTED]
|
|
tel: tel2:
|
+94-11-2673973 +94-11-2696648
|
|
|
---------------------------------------------------------------------
To
unsubscribe, e-mail: [EMAIL PROTECTED]
For
additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To
unsubscribe, e-mail: [EMAIL PROTECTED]
For
additional commands, e-mail:
[EMAIL PROTECTED]