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 Jason <ja...@yahoo.com> on 2005/10/27 22:49:46 UTC
Having trouble factorying a progressive pull parser
Hello,
I'm trying to use the methods in the interface
org.apache.xerces.xni.parser.XMLPullParserConfiguration
and I can't figure out how to create an instance of a
parser which implements it. I've made two attempts -
the first is to run this code:
//Begin Code
public static void main(String[] args) throws
Exception
{
XMLParserConfiguration parserConfig = null;
// create parser configuration
try
{
parserConfig =
(XMLParserConfiguration)ObjectFactory.newInstance("org.apache.xerces.xni.parser.XMLPullParserConfiguration",
ObjectFactory.findClassLoader(),
true);
}
catch (Exception e)
{
System.err.println("error: Unable to instantiate
parser configuration
org.apache.xerces.xni.parser.XMLPullParserConfiguration");
}
// XMLDocumentParser parser = new
XMLDocumentParser(parserConfig);
//End Code
Getting this code to compile involved copying
ObjectFactory.java and SecuritySupport.java from the
samples/xni directory and building them along with my
test code. When I run the class I get this error:
Exception in thread "main"
ObjectFactory$ConfigurationError: Provider
org.apache.xerces.xni.parser.XMLPullParserConfiguration
could not be instantiated:
java.lang.InstantiationException:
org.apache.xerces.xni.parser.XMLPullParserConfiguration
at
ObjectFactory.newInstance(ObjectFactory.java:346)
at PullParserTest.main(PullParserTest.java:35)
I also tried launching the VM like so:
java
-Dorg.apache.xerces.xni.parser.XMLParserConfiguration=org.apache.xerces.xni.parser.XMLPullParserConfiguration
PullParserTest ADMAdapterOutput.xml
but that didn't help. I've poked around the
documentation quite a bit but I'm still in the dark.
Am I making this harder than need be? Can anyone
provide me with a bit of code to create a PullParser
instance? Thanks in advance.
-jason
__________________________________
Yahoo! FareChase: Search multiple travel sites in one click.
http://farechase.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org
Re: Having trouble factorying a progressive pull parser
Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Jason,
The SAXParser has a constructor [1] which takes an XMLParserConfiguration
as a parameter. You could create the parser using this constructor and
still get the benefit of pull parser configuration if you call the
setupInputSource() and parse() method on the parser configuration (instead
of the parser() method on the SAXParser). The configuration will send the
document events to the SAXParser which will in turn be reported to your
ContentHandler.
Hope that helps.
[1]
http://xerces.apache.org/xerces2-j/javadocs/xerces2/org/apache/xerces/parsers/SAXParser.html#SAXParser(org.apache.xerces.xni.parser.XMLParserConfiguration)
Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org
Jason <ja...@yahoo.com> wrote on 10/31/2005 12:51:13 PM:
> Michael,
>
> Thanks again. I was slightly misled by the names
> ending with 'Configuration' in that I thought they
> should somehow be used to configure a parser rather
> than to act as a parser themselves. In any event, I
> think I've finally got things straightened out. Just
> to make sure I'm not confused: if I'm using the xni
> PullParserConfiguration I have to use the
> xni.XMLDocumentHandler class in order to get my
> callbacks rather than the normal ContentHandler. Is
> that true or is there some way to use ContentHandler
> in conjunction with a pull parser? Thanks again for
> your help.
>
> -jason
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org
Re: Having trouble factorying a progressive pull parser
Posted by Jason <ja...@yahoo.com>.
Michael,
Thanks again. I was slightly misled by the names
ending with 'Configuration' in that I thought they
should somehow be used to configure a parser rather
than to act as a parser themselves. In any event, I
think I've finally got things straightened out. Just
to make sure I'm not confused: if I'm using the xni
PullParserConfiguration I have to use the
xni.XMLDocumentHandler class in order to get my
callbacks rather than the normal ContentHandler. Is
that true or is there some way to use ContentHandler
in conjunction with a pull parser? Thanks again for
your help.
-jason
--- Michael Glavassevich <mr...@ca.ibm.com> wrote:
> Jason,
>
> There's no magic service for obtaining
> XMLPullParserConfigurations. The
> default parser configuration:
>
org.apache.xerces.parsers.XIncludeAwareParserConfiguration
> implements
>
org.apache.xerces.xni.parser.XMLPullParserConfiguration.
> It has public
> constructors. You can create it directly. The other
> available parser
> configurations are listed here [1].
>
> Thanks.
>
> [1]
> http://xml.apache.org/xerces2-j/faq-xni.html#faq-3
>
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org
>
> Jason <ja...@yahoo.com> wrote on 10/27/2005
> 04:49:46 PM:
>
> > Hello,
> >
> > I'm trying to use the methods in the interface
> >
>
org.apache.xerces.xni.parser.XMLPullParserConfiguration
> > and I can't figure out how to create an instance
> of a
> > parser which implements it. I've made two
> attempts -
> > the first is to run this code:
> >
> > //Begin Code
> > public static void main(String[] args) throws
> > Exception
> > {
> > XMLParserConfiguration parserConfig = null;
> >
> > // create parser configuration
> > try
> > {
> > parserConfig =
> >
> >
>
(XMLParserConfiguration)ObjectFactory.newInstance("org.apache.
> > xerces.xni.parser.XMLPullParserConfiguration",
> >
> ObjectFactory.findClassLoader(),
> > true);
> >
> > }
> > catch (Exception e)
> > {
> > System.err.println("error: Unable to
> instantiate
> > parser configuration
> >
>
org.apache.xerces.xni.parser.XMLPullParserConfiguration");
> > }
> >
> > // XMLDocumentParser parser = new
> > XMLDocumentParser(parserConfig);
> > //End Code
> >
> > Getting this code to compile involved copying
> > ObjectFactory.java and SecuritySupport.java from
> the
> > samples/xni directory and building them along with
> my
> > test code. When I run the class I get this error:
> >
> > Exception in thread "main"
> > ObjectFactory$ConfigurationError: Provider
> >
>
org.apache.xerces.xni.parser.XMLPullParserConfiguration
> > could not be instantiated:
> > java.lang.InstantiationException:
> >
>
org.apache.xerces.xni.parser.XMLPullParserConfiguration
> > at
> > ObjectFactory.newInstance(ObjectFactory.java:346)
> > at
> PullParserTest.main(PullParserTest.java:35)
> >
> > I also tried launching the VM like so:
> >
> > java
> >
>
-Dorg.apache.xerces.xni.parser.XMLParserConfiguration=org.apache.
> > xerces.xni.parser.XMLPullParserConfiguration
> > PullParserTest ADMAdapterOutput.xml
> >
> > but that didn't help. I've poked around the
> > documentation quite a bit but I'm still in the
> dark.
> > Am I making this harder than need be? Can anyone
> > provide me with a bit of code to create a
> PullParser
> > instance? Thanks in advance.
> >
> > -jason
> >
> >
> >
> >
> >
> > __________________________________
> > Yahoo! FareChase: Search multiple travel sites in
> one click.
> > http://farechase.yahoo.com
> >
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> j-users-unsubscribe@xerces.apache.org
> > For additional commands, e-mail:
> j-users-help@xerces.apache.org
> >
>
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail:
> j-users-help@xerces.apache.org
>
>
__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org
Re: Having trouble factorying a progressive pull parser
Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Jason,
There's no magic service for obtaining XMLPullParserConfigurations. The
default parser configuration:
org.apache.xerces.parsers.XIncludeAwareParserConfiguration implements
org.apache.xerces.xni.parser.XMLPullParserConfiguration. It has public
constructors. You can create it directly. The other available parser
configurations are listed here [1].
Thanks.
[1] http://xml.apache.org/xerces2-j/faq-xni.html#faq-3
Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org
Jason <ja...@yahoo.com> wrote on 10/27/2005 04:49:46 PM:
> Hello,
>
> I'm trying to use the methods in the interface
> org.apache.xerces.xni.parser.XMLPullParserConfiguration
> and I can't figure out how to create an instance of a
> parser which implements it. I've made two attempts -
> the first is to run this code:
>
> //Begin Code
> public static void main(String[] args) throws
> Exception
> {
> XMLParserConfiguration parserConfig = null;
>
> // create parser configuration
> try
> {
> parserConfig =
>
> (XMLParserConfiguration)ObjectFactory.newInstance("org.apache.
> xerces.xni.parser.XMLPullParserConfiguration",
> ObjectFactory.findClassLoader(),
> true);
>
> }
> catch (Exception e)
> {
> System.err.println("error: Unable to instantiate
> parser configuration
> org.apache.xerces.xni.parser.XMLPullParserConfiguration");
> }
>
> // XMLDocumentParser parser = new
> XMLDocumentParser(parserConfig);
> //End Code
>
> Getting this code to compile involved copying
> ObjectFactory.java and SecuritySupport.java from the
> samples/xni directory and building them along with my
> test code. When I run the class I get this error:
>
> Exception in thread "main"
> ObjectFactory$ConfigurationError: Provider
> org.apache.xerces.xni.parser.XMLPullParserConfiguration
> could not be instantiated:
> java.lang.InstantiationException:
> org.apache.xerces.xni.parser.XMLPullParserConfiguration
> at
> ObjectFactory.newInstance(ObjectFactory.java:346)
> at PullParserTest.main(PullParserTest.java:35)
>
> I also tried launching the VM like so:
>
> java
> -Dorg.apache.xerces.xni.parser.XMLParserConfiguration=org.apache.
> xerces.xni.parser.XMLPullParserConfiguration
> PullParserTest ADMAdapterOutput.xml
>
> but that didn't help. I've poked around the
> documentation quite a bit but I'm still in the dark.
> Am I making this harder than need be? Can anyone
> provide me with a bit of code to create a PullParser
> instance? Thanks in advance.
>
> -jason
>
>
>
>
>
> __________________________________
> Yahoo! FareChase: Search multiple travel sites in one click.
> http://farechase.yahoo.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org