You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Ranjith Kodikara <ra...@dmsswt.com> on 2004/11/04 06:54:02 UTC
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
ranjith@dmsswt.com
Ranjith Kodikara
Systems Engineer DMS Software Technologies
165, Dharmapala Mawatha,
Colombo 00700
ranjith@dmsswt.com tel:
tel2: +94-11-2673973
+94-11-2696648
Xerces2-J vs Xerces
Posted by IndianAtTech <in...@gmail.com>.
Hello All,
I would like to know the difference between Xerces2-J and Xerces Parsers
I just see following links
http://www.xmlhack.com/read.php?item=1762
http://xml.apache.org/xerces2-j/
Thanks
Sudhakar
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
Re: XInclude parse="text" producing & # x D ;
Posted by Michael Glavassevich <mr...@ca.ibm.com>.
XML processors transform sequences of #xD #xA and any #xD that is not
followed by #xA to a single #xA character on input [1]. If the serializer
doesn't write #xD as a reference then they'll get transformed into #xA
when the document is read again.
[1] http://www.w3.org/TR/2004/REC-xml-20040204/#sec-line-ends
Robert Koberg <ro...@koberg.com> wrote on 11/05/2004 02:41:23 PM:
> Michael Glavassevich wrote:
>
> >
> > Hello Rob,
> >
> > When parse="text" the text from whatever href points to is included
> > directly. If the text being included contains line breaks they'll end
up
> > in the result. A serializer will write these as character references
so
> > that they can be round-tripped when the document is read again.
>
>
> OK, thanks. But why doesn't it use a numeric entity that can be easily
> understood?
>
> Also, the visible line breaks are still there and the entity shows up as
> well. That is, they are not showing up like:
>
> String var1=1;& # x D ;String var2=2;
>
> rather, they show like:
>
> String var1=1;& # x D ;
> String var2=2;
>
> I am transforming the source into a JSP (using the JSP XML syntax) and
> the JSP parser chokes on the undefined entity.
>
> Oh well, I can just wrap the text in an element.
>
> thanks,
> -Rob
>
>
> >
> > Robert Koberg <ro...@koberg.com> wrote on 11/05/2004 01:48:27 PM:
> >
> > > Hi,
> > >
> > > I am trying to use XInclude to include some text in the XML source
used
> > > in a transformation. If I wrap the text in an element and don't use
> > > parse="text" all is good.
> > >
> > > When I use something like:
> > >
> > > <!-- also used US-ASCII and ISO-8859-1 for @encoding -->
> > > <xi:xinclude
> > > encoding="UTF-8"
> > > href="something.txt"
> > > parse="text">
> > > <xi:fallback/>
> > > </xi:xinclude>
> > >
> > > I get a character entity representing line endings (& # x D ;).
> > >
> > > Is there some way to avoid this? (I have searched and have not
found any
> > > references to this problem)
> > >
> > > thanks,
> > > -Rob
> > >
> > >
---------------------------------------------------------------------
> > > To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> > > For additional commands, e-mail: xerces-j-user-help@xml.apache.org
> > >
> >
> > Michael Glavassevich
> > XML Parser Development
> > IBM Toronto Lab
> > E-mail: mrglavas@ca.ibm.com
> > E-mail: mrglavas@apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>
Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org
Re: XInclude parse="text" producing & # x D ;
Posted by Robert Koberg <ro...@koberg.com>.
Michael Glavassevich wrote:
>
> Hello Rob,
>
> When parse="text" the text from whatever href points to is included
> directly. If the text being included contains line breaks they'll end up
> in the result. A serializer will write these as character references so
> that they can be round-tripped when the document is read again.
OK, thanks. But why doesn't it use a numeric entity that can be easily
understood?
Also, the visible line breaks are still there and the entity shows up as
well. That is, they are not showing up like:
String var1=1;& # x D ;String var2=2;
rather, they show like:
String var1=1;& # x D ;
String var2=2;
I am transforming the source into a JSP (using the JSP XML syntax) and
the JSP parser chokes on the undefined entity.
Oh well, I can just wrap the text in an element.
thanks,
-Rob
>
> Robert Koberg <ro...@koberg.com> wrote on 11/05/2004 01:48:27 PM:
>
> > Hi,
> >
> > I am trying to use XInclude to include some text in the XML source used
> > in a transformation. If I wrap the text in an element and don't use
> > parse="text" all is good.
> >
> > When I use something like:
> >
> > <!-- also used US-ASCII and ISO-8859-1 for @encoding -->
> > <xi:xinclude
> > encoding="UTF-8"
> > href="something.txt"
> > parse="text">
> > <xi:fallback/>
> > </xi:xinclude>
> >
> > I get a character entity representing line endings (& # x D ;).
> >
> > Is there some way to avoid this? (I have searched and have not found any
> > references to this problem)
> >
> > thanks,
> > -Rob
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> > For additional commands, e-mail: xerces-j-user-help@xml.apache.org
> >
>
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
Re: XInclude parse="text" producing & # x D ;
Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hello Rob,
When parse="text" the text from whatever href points to is included
directly. If the text being included contains line breaks they'll end up
in the result. A serializer will write these as character references so
that they can be round-tripped when the document is read again.
Robert Koberg <ro...@koberg.com> wrote on 11/05/2004 01:48:27 PM:
> Hi,
>
> I am trying to use XInclude to include some text in the XML source used
> in a transformation. If I wrap the text in an element and don't use
> parse="text" all is good.
>
> When I use something like:
>
> <!-- also used US-ASCII and ISO-8859-1 for @encoding -->
> <xi:xinclude
> encoding="UTF-8"
> href="something.txt"
> parse="text">
> <xi:fallback/>
> </xi:xinclude>
>
> I get a character entity representing line endings (& # x D ;).
>
> Is there some way to avoid this? (I have searched and have not found any
> references to this problem)
>
> thanks,
> -Rob
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>
Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org
XInclude parse="text" producing & # x D ;
Posted by Robert Koberg <ro...@koberg.com>.
Hi,
I am trying to use XInclude to include some text in the XML source used
in a transformation. If I wrap the text in an element and don't use
parse="text" all is good.
When I use something like:
<!-- also used US-ASCII and ISO-8859-1 for @encoding -->
<xi:xinclude
encoding="UTF-8"
href="something.txt"
parse="text">
<xi:fallback/>
</xi:xinclude>
I get a character entity representing line endings (& # x D ;).
Is there some way to avoid this? (I have searched and have not found any
references to this problem)
thanks,
-Rob
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
Re: Problem with SAX Parsing in Xerces
Posted by ra...@freddiemac.com.
Your original message says this:
> 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.
But when you create an instance of the parser, you create a new instance
SurveyReader and pass that as the handler to the parser. So the
SurveyReader that is created in the code above is never used by your
parser.
Hope that helps.
-ramin
"Ranjith Kodikara" <ra...@dmsswt.com>
11/05/2004 01:13 AM
Please respond to
xerces-j-user@xml.apache.org
To
xerces-j-user@xml.apache.org
cc
Subject
Re: Problem with SAX Parsing in Xerces
Dear Ramin,
Thanks a lot for your reply. But The xml is correctly parsing. this is the
code I use for that
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 -----
From: ramin_rad@freddiemac.com
To: xerces-j-user@xml.apache.org
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" <ra...@dmsswt.com>
11/04/2004 12:54 AM
Please respond to
xerces-j-user@xml.apache.org
To
xerces-j-user@xml.apache.org
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
ranjith@dmsswt.com
Ranjith Kodikara
Systems Engineer
DMS Software Technologies
165, Dharmapala Mawatha,
Colombo 00700
ranjith@dmsswt.com
tel:
tel2:
+94-11-2673973
+94-11-2696648
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
Re: Problem with SAX Parsing in Xerces
Posted by Ranjith Kodikara <ra...@dmsswt.com>.
Dear Ramin,
Thanks a lot for your reply. But The xml is correctly parsing. this is the code I use for that
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 -----
From: ramin_rad@freddiemac.com
To: xerces-j-user@xml.apache.org
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" <ra...@dmsswt.com>
11/04/2004 12:54 AM Please respond to
xerces-j-user@xml.apache.org
To xerces-j-user@xml.apache.org
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
ranjith@dmsswt.com
Ranjith Kodikara
Systems Engineer DMS Software Technologies
165, Dharmapala Mawatha,
Colombo 00700
ranjith@dmsswt.com tel:
tel2: +94-11-2673973
+94-11-2696648
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
------------------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
Re: Problem with SAX Parsing in Xerces
Posted by ra...@freddiemac.com.
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" <ra...@dmsswt.com>
11/04/2004 12:54 AM
Please respond to
xerces-j-user@xml.apache.org
To
xerces-j-user@xml.apache.org
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
ranjith@dmsswt.com
Ranjith Kodikara
Systems Engineer
DMS Software Technologies
165, Dharmapala Mawatha,
Colombo 00700
ranjith@dmsswt.com
tel:
tel2:
+94-11-2673973
+94-11-2696648
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org