I'm using Sun's implementation of StAX parser to parse some large xml
files. The file size is about 1.5MB. I'm using the XMLEventReader interface to parse xmls which consists of many elements like these. The SCRIPT element contains sql queries which can be very large at times.
The problem I'm facing is that at times the character event returns me only a part of the text in the SCRIPT element. It happens if there are spaces and newlines. If the text changes by a single character ( add
or remove a character somewhere ), it starts working fine.
This looks like a general XML parsing problem or it might be something related to the stax parser. Is there any limit to how many characters the character event can have at a time ?
Any thoughts on this is highly appreciated.
hi Sam,
in contrast o XmlPull API in STAX there is no requirement to retrn all text inside element in one event instead youmay get multiple - just modify your code to expect it.
Hi,
I hope this post is relevant to this forum.
I'm using Sun's implementation of StAX parser to parse some large xml
files. The file size is about 1.5MB. I'm using the XMLEventReader
interface to parse xmls which consists of many elements like these.
The SCRIPT element contains sql queries which can be very large at times.
The problem I'm facing is that at times the character event returns me
only a part of the text in the SCRIPT element. It happens if there are
spaces and newlines. If the text changes by a single character ( add
or remove a character somewhere ), it starts working fine.
This looks like a general XML parsing problem or it might be something
related to the stax parser. Is there any limit to how many characters
the character event can have at a time ?
Any thoughts on this is highly appreciated.
Thanks
Sam
<BUILD VERSION="2250.0000">
<CHANGE NUMBER="0">
<SCRIPT>
<![CDATA[
ALTER TABLE INVOICE ALTER COLUMN
INVOICE_SOLD_TO_PUB_X_REF NVARCHAR(40) NULL
;
]]>
</SCRIPT>
</CHANGE>
<CHANGE NUMBER="1">
</CHANGE>
</BUILD>
Alek,
Thanks for the quick reply!
I believe that XPP3 is set to be namespace aware, as the factory
method I call to give me an XmlInfosetBuilder object sets this flag
to true for me.
Here is a full Java class that I run. I use the latest XPP3 from the
website link: http://www.extreme.indiana.edu/dist/java-
repository/xpp3/distributions/xpp3-1.1.4c_all.zip
I have extended the XPath functions to include the 'matches' and a
half-implementation of the 'index-of', but I have not touched any of
the underlying "base" code, and I have tested with a non-modified
version to verify.
I still think that I am missing something, probably something
obvious like that setNamespaceAware setter, but I just can't seem to
figure out what.
EG
import java.io.StringReader;
import java.util.ArrayList;
import org.xmlpull.v1.builder.XmlDocument;
import org.xmlpull.v1.builder.XmlInfosetBuilder;
import org.xmlpull.v1.builder.xpath.Xb1XPath;
public class Tester {
/**
* Tester class for quick tests
*
* @param args
*/
public static void main(String[] args) {
String xml = "<ns1:A xmlns:ns1=\"http://some.url.org\">" +
"<ns1:B>" +
"<ns1:C xyz=\"test\"/>" +
"</ns1:B>" +
"</ns1:A>";
try {
XmlInfosetBuilder builder = XmlInfosetBuilder.newInstance();
XmlDocument doc = builder.parseReader(new StringReader(xml));
Xb1XPath predicateObj = new Xb1XPath("/ns1:A/ns1:B");
Object retObj = predicateObj.evaluate(doc);
if (retObj != null) {
System.out.println(retObj.getClass().getName());
if (retObj instanceof ArrayList)
System.out.println(((ArrayList) retObj).size());
} else
System.out.println("null");
} catch (Exception e) {
e.printStackTrace();
}
}
}
--- In xmlpull-user@yahoogroups.com, "Aleksander Slominski"
<aslom@...> wrote:
>
> XPath with namespaces definitely works - i used it many times :)
>
> make sure that XML parsed is with namespace aware builder mdoe set
on?
>
> and if it does nto help please post a full java file that can be
executed to
> reproduce the error including what exactly XXP3 jar file you used.
>
> thanks,
>
> Alek
>
>
> On 10/30/07, lipafrog <lipafrog@...> wrote:
> >
> > Hi all,
> >
> > I am using XPP3 to parse a document containing a custom namespace
> > and use an XPath predicate to pull out an element, but XPP3 does
not
> > find the element! Without the namespace this example works fine,
add
> > the namespace and it returns nothing. Have I failed to use XML
> > namespaces/XPP3 correctly? If so, could someone please point out
how?
> >
> > Thanks!
> > EG
> >
> > The XML is like:
> > <ns1:A xmlns:ns1="http://some.url.org">
> > <ns1:B>
> > <ns1:C xyz="test"/>
> > </ns1:B>
> > </ns1:A>
> >
> > The code I try to use looks like, and returns an empty ArrayList:
> > Xb1XPath predicateObj = new Xb1XPath("/ns1:A/ns1:B");
> >
> > Object retObj = predicateObj.evaluate(docObj);
> >
> > if (retObj != null) {
> > System.out.println(retObj.getClass().getName());
> >
> > if (retObj instanceof ArrayList) {
> > System.out.println(((ArrayList) retObj).size());
> > }
> > } else
> > System.out.println("null");
> >
> >
> >
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
>
>
> --
> ---
> The best way to predict the future is to invent it - Alan Kay
>
I am using XPP3 to parse a document containing a custom namespace and use an XPath predicate to pull out an element, but XPP3 does not
find the element! Without the namespace this example works fine, add the namespace and it returns nothing. Have I failed to use XML namespaces/XPP3 correctly? If so, could someone please point out how?
Thanks!
EG
The XML is like: <ns1:A xmlns:ns1="http://some.url.org"> <ns1:B> <ns1:C xyz="test"/> </ns1:B> </ns1:A>
The code I try to use looks like, and returns an empty ArrayList: Xb1XPath predicateObj = new Xb1XPath("/ns1:A/ns1:B");
Object retObj = predicateObj.evaluate(docObj);
if (retObj != null) {
System.out.println(retObj.getClass().getName());
Hi all,
I am using XPP3 to parse a document containing a custom namespace
and use an XPath predicate to pull out an element, but XPP3 does not
find the element! Without the namespace this example works fine, add
the namespace and it returns nothing. Have I failed to use XML
namespaces/XPP3 correctly? If so, could someone please point out how?
Thanks!
EG
The XML is like:
<ns1:A xmlns:ns1="http://some.url.org">
<ns1:B>
<ns1:C xyz="test"/>
</ns1:B>
</ns1:A>
The code I try to use looks like, and returns an empty ArrayList:
Xb1XPath predicateObj = new Xb1XPath("/ns1:A/ns1:B");
Object retObj = predicateObj.evaluate(docObj);
if (retObj != null) {
System.out.println(retObj.getClass().getName());
if (retObj instanceof ArrayList) {
System.out.println(((ArrayList) retObj).size());
}
} else
System.out.println("null");
Hello, programmers.
[I know that this is not exactly a xmlpull question but, if I am not
mistaken, kXml2 does use xmlpull.]
I read an article about optimizations and the article stated that one
should NOT put source into a package well that was easy enough to do.
However, it also went on to suggest that one should remove third
party libraries from their packages rather than just dump it into the
project. How do I do this? I am using "kXml2" parser and I can't see
how to unjar it and remove it from it's package unless I get the
source code and do it manually.
The reasoning behind this is that java generates a lot of overhead
when handling classes that are part of a package.
Any suggests on how to remove 3rd party libraries from their packages?
Thanks,
-------
JavaME (J2ME), Java, C & C# Developer
CV: http://docs.google.com/Doc?id=dt6fqcn_51dn8gds
prasad wrote:
> I tried to run the sample program of xpp3 MyXmlPullApp.java with
> parametr of a sample xml file containing external entities defined in
> dtd is failed to execute with the following error message
>
> Exception in thread "main" org.xmlpull.v1.XmlPullParserException: could
> not resolve entity named 'para' (position: START_TAG
> seen ...<italic>References are to paragraph (¶... @7:114)
> at org.xmlpull.mxp1.MXParser.nextImpl(MXParser.java:1282)
> at org.xmlpull.mxp1.MXParser.next(MXParser.java:1093)
> at com.xpp.XmlPullAppFile.processDocument
> (XmlPullAppFile.java:89)
> at com.xpp.XmlPullAppFile.main(XmlPullAppFile.java:51)
>
> Can any one help, how to resolve the entity references
>
XPP3 does not support DTDs - as workaround for entities you can define
your own replacement.
best,
Alek
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
--
The best way to predict the future is to invent it - Alan Kay
I tried to run the sample program of xpp3 MyXmlPullApp.java with
parametr of a sample xml file containing external entities defined in
dtd is failed to execute with the following error message
Exception in thread "main" org.xmlpull.v1.XmlPullParserException: could
not resolve entity named 'para' (position: START_TAG
seen ...<italic>References are to paragraph (¶... @7:114)
at org.xmlpull.mxp1.MXParser.nextImpl(MXParser.java:1282)
at org.xmlpull.mxp1.MXParser.next(MXParser.java:1093)
at com.xpp.XmlPullAppFile.processDocument
(XmlPullAppFile.java:89)
at com.xpp.XmlPullAppFile.main(XmlPullAppFile.java:51)
Can any one help, how to resolve the entity references
diehardwomble wrote:
> Hi,
> I am using the kXML API in particular the XmlSerializer however all
> my xml tags are generated with a prefix on them for example:
>
> If i was trying to generate:
>
> <test id='123'></test>
>
> it is coming out as:
>
> <n0:test n0:id='123'><n0:test>
>
> i have tried using
>
> setPrefix("",NAMESPACE)
>
> however this at best only manages to do:
>
> <test n0:id='123'></n0:test>
>
> am I doing something wrong? is more information required?
>
looks like a bug in kXML - do use the latest version? did you try to run
the same code with XPP3 to verify?
best,
Alek
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
--
The best way to predict the future is to invent it - Alan Kay
Hi,
I am using the kXML API in particular the XmlSerializer however all
my xml tags are generated with a prefix on them for example:
If i was trying to generate:
<test id='123'></test>
it is coming out as:
<n0:test n0:id='123'><n0:test>
i have tried using
setPrefix("",NAMESPACE)
however this at best only manages to do:
<test n0:id='123'></n0:test>
am I doing something wrong? is more information required?
Aleksander Slominski wrote:
> Martin Woolley wrote:
>
>> Hi
>>
>> I'm stress testing an application that uses XPP3. I'm seeing the
>> following stacktrace sporadically:
>>
>> java.io.EOFException: no more data available
>> Thread-5: at org.xmlpull.mxp1.MXParser.fillBuf(MXParser.java:2659)
>> Thread-5: at org.xmlpull.mxp1.MXParser.more(MXParser.java:2666)
>> Thread-5: at
>> org.xmlpull.mxp1.MXParser.parseProlog(MXParser.java:1385)
>> Thread-5: at org.xmlpull.mxp1.MXParser.nextImpl(MXParser.java:1370)
>> Thread-5: at org.xmlpull.mxp1.MXParser.next(MXParser.java:1111)
>> Thread-5: at
>>
com.nmss.ms.agent.api.XppStreamHandler.processDocument(XppStreamHandler.java:67)
>> Thread-5: at com.nmss.ms.agent.api.ApiWorker.run(ApiWorker.java:193)
>> Thread-5: at java.lang.Thread.run(Thread.java:534)
>>
>>
>> I have checked the XML input document and it looks fine.
>>
>> My instincts tell me I've hit some kind of synchronisation issue....
>> but I could be wildly wrong.
>>
>>
> are you using the same parser instance in multiple threads? this is not
> supported. as noted in docs and as it is usual for XML parser: XPP3 is
> not multi thread safe and each thread should have its own instance of
> parser. you can use parser pool (see xmlpull.org addons) if you want to
> recycle parser instances (run some perf test with and without pooling ot
> make sure you get optimal perf)
>
one more addition maybe it is obvious but ... you can use the same
instance in multiple threads *if* you will do all synchronization to
make sure no two threads are accessing parser (and its input) in the
same time.
best,
Alek
>> Are there are known issues that produce this Exception?
>>
>> Thank in anticipation
>>
>> Martin
>>
>>
>>
>>
>> Yahoo! Groups Links
>>
>>
>>
>>
>>
>
>
>
--
The best way to predict the future is to invent it - Alan Kay
Martin Woolley wrote:
> Hi
>
> I'm stress testing an application that uses XPP3. I'm seeing the
> following stacktrace sporadically:
>
> java.io.EOFException: no more data available
> Thread-5: at org.xmlpull.mxp1.MXParser.fillBuf(MXParser.java:2659)
> Thread-5: at org.xmlpull.mxp1.MXParser.more(MXParser.java:2666)
> Thread-5: at
> org.xmlpull.mxp1.MXParser.parseProlog(MXParser.java:1385)
> Thread-5: at org.xmlpull.mxp1.MXParser.nextImpl(MXParser.java:1370)
> Thread-5: at org.xmlpull.mxp1.MXParser.next(MXParser.java:1111)
> Thread-5: at
>
com.nmss.ms.agent.api.XppStreamHandler.processDocument(XppStreamHandler.java:67)
> Thread-5: at com.nmss.ms.agent.api.ApiWorker.run(ApiWorker.java:193)
> Thread-5: at java.lang.Thread.run(Thread.java:534)
>
>
> I have checked the XML input document and it looks fine.
>
> My instincts tell me I've hit some kind of synchronisation issue....
> but I could be wildly wrong.
>
are you using the same parser instance in multiple threads? this is not
supported. as noted in docs and as it is usual for XML parser: XPP3 is
not multi thread safe and each thread should have its own instance of
parser. you can use parser pool (see xmlpull.org addons) if you want to
recycle parser instances (run some perf test with and without pooling ot
make sure you get optimal perf)
HTH,
Alek
> Are there are known issues that produce this Exception?
>
> Thank in anticipation
>
> Martin
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
--
The best way to predict the future is to invent it - Alan Kay
Hi
I'm stress testing an application that uses XPP3. I'm seeing the
following stacktrace sporadically:
java.io.EOFException: no more data available
Thread-5: at org.xmlpull.mxp1.MXParser.fillBuf(MXParser.java:2659)
Thread-5: at org.xmlpull.mxp1.MXParser.more(MXParser.java:2666)
Thread-5: at
org.xmlpull.mxp1.MXParser.parseProlog(MXParser.java:1385)
Thread-5: at org.xmlpull.mxp1.MXParser.nextImpl(MXParser.java:1370)
Thread-5: at org.xmlpull.mxp1.MXParser.next(MXParser.java:1111)
Thread-5: at
com.nmss.ms.agent.api.XppStreamHandler.processDocument(XppStreamHandler.java:67)
Thread-5: at com.nmss.ms.agent.api.ApiWorker.run(ApiWorker.java:193)
Thread-5: at java.lang.Thread.run(Thread.java:534)
I have checked the XML input document and it looks fine.
My instincts tell me I've hit some kind of synchronisation issue....
but I could be wildly wrong.
Are there are known issues that produce this Exception?
Thank in anticipation
Martin
Dear Aleksander
Thanks for your help; I am very pleased with the ease of using XMLPullParser.
Keep up the good work!
Phil
>Phil Troy wrote:
> > Dear Aleksander
> >
> > Hi!
> >
> > I bypassed the problem of the missing XmlPullParserFactory class by
> > creating the relevant packages and creating classes within them as
> > needed so that I now have the following projects/classes:
> >
> > - org.xmlpull.v1
> > - XmlPullParser.java
> > - XmlPullParserException
> > - XmlPullParserFactory
> > - XmlSerializer
> >
> > - org.xmlpull.mxp1
> > - MxParser.java
> >
> > But now, when I run the following statement it throws an exception on
> > the following line of code
> >
> > XmlPullParserFactory factory =
> >
>
XmlPullParserFactory.newInstance(System.getProperty(XmlPullParserFactory.PROPERT\
Y_NAME),
>
> > null);
> >
> > I presume that it is because I am not properly setting the class to
> > MxParser.java - if that is the problem, can you please tell me how to
> > do that? I did look at the
> >
> > Class XmlPullParserFactory documentation, and did see the reference to
> >
> > Thread.getContextClassLoader().getClass() but I don't know how to get
> > that to work.
> >
>calling System.getProperty(XmlPullParserFactory.PROPERTY_NAME) allwos
>you to override parser impl class with system property. in case if it is
>null then factory loads parse class impl name from special file in
>META-INF directory and if you donot have this file it fails
>
>you can by pass it by simply calling:
>
>XmlPullParserFactory.newInstance("org.xmlpull.mxp1.MXParser",null)
>
>or simply
>
>XmlPullParser pp = new org.xmlpull.mxp1.MXParser()
>
>anyway you should not need to do anything like this if you used
>xpp3-1.1.4c.jar - in such case factory should just work so i suspect
>there must be something eerie in your CLASSPATH project. it may be wort
>to create new workspace and bran new project in eclipse and see how
>things work in such case.
>
>best,
>
>alek
>
>
Philip M. Troy, Ph.D.,
Decision Support Systems Analyst
PhilTroy@...
www.PhilTroy.com
pledreau wrote:
> Hello, in my xsl file I have
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> <xsl:output method="xml" version="1.0"/>
> ...
> <xmlpost>
> <xsl:value-of select="$donnee" disable-output-
> escaping="yes"/>
> </xmlpost>
> ...
>
> in my java code :
> ...
> transformer.transform(new DOMSource((Document)arbre), new
> StreamResult(stream));
> ...
>
> When I run this program I obtain :
> org.xmlpull.v1.XmlPullParserException: entity reference name can not
> contain character =' (position: TEXT seen ...<xmlpost>Ap
> pl=WEBACC&Ident=... @21:28)
>
> That happens on the following string :
> /cgi-bin/emxml?Appl=WEBACC&Ident=00000000&Secret=00
>
> I'm using disable-output-escaping="yes" to obtain in my output stream
> <xmlpost>/cgi-bin/emxml?
> Appl=WEBACC&Ident=00000000&Secret=00</xmlpost>
>
> instead of
>
> <xmlpost>/cgi-bin/emxml?
> Appl=WEBACC&Amp;Ident=00000000&Amp;Secret=00</xmlpost>
>
> The running jre is 1.2
>
> How can I solve this problem ?
>
"&Ident" is interpeted as name of entity - this is not allowed in XML
and must be escaped use & (not &Amp;) and all should work fine.
best,
alek
> thanks in advance
>
> PLedreau
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
--
The best way to predict the future is to invent it - Alan Kay
Hello, in my xsl file I have
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0"/>
...
<xmlpost>
<xsl:value-of select="$donnee" disable-output-
escaping="yes"/>
</xmlpost>
...
in my java code :
...
transformer.transform(new DOMSource((Document)arbre), new
StreamResult(stream));
...
When I run this program I obtain :
org.xmlpull.v1.XmlPullParserException: entity reference name can not
contain character =' (position: TEXT seen ...<xmlpost>Ap
pl=WEBACC&Ident=... @21:28)
That happens on the following string :
/cgi-bin/emxml?Appl=WEBACC&Ident=00000000&Secret=00
I'm using disable-output-escaping="yes" to obtain in my output stream
<xmlpost>/cgi-bin/emxml?
Appl=WEBACC&Ident=00000000&Secret=00</xmlpost>
instead of
<xmlpost>/cgi-bin/emxml?
Appl=WEBACC&Amp;Ident=00000000&Amp;Secret=00</xmlpost>
The running jre is 1.2
How can I solve this problem ?
thanks in advance
PLedreau
Phil Troy wrote:
> Dear Aleksander
>
> Hi!
>
> I bypassed the problem of the missing XmlPullParserFactory class by
> creating the relevant packages and creating classes within them as
> needed so that I now have the following projects/classes:
>
> - org.xmlpull.v1
> - XmlPullParser.java
> - XmlPullParserException
> - XmlPullParserFactory
> - XmlSerializer
>
> - org.xmlpull.mxp1
> - MxParser.java
>
> But now, when I run the following statement it throws an exception on
> the following line of code
>
> XmlPullParserFactory factory =
>
XmlPullParserFactory.newInstance(System.getProperty(XmlPullParserFactory.PROPERT\
Y_NAME),
> null);
>
> I presume that it is because I am not properly setting the class to
> MxParser.java - if that is the problem, can you please tell me how to
> do that? I did look at the
>
> Class XmlPullParserFactory documentation, and did see the reference to
>
> Thread.getContextClassLoader().getClass() but I don't know how to get
> that to work.
>
calling System.getProperty(XmlPullParserFactory.PROPERTY_NAME) allwos
you to override parser impl class with system property. in case if it is
null then factory loads parse class impl name from special file in
META-INF directory and if you donot have this file it fails
you can by pass it by simply calling:
XmlPullParserFactory.newInstance("org.xmlpull.mxp1.MXParser",null)
or simply
XmlPullParser pp = new org.xmlpull.mxp1.MXParser()
anyway you should not need to do anything like this if you used
xpp3-1.1.4c.jar - in such case factory should just work so i suspect
there must be something eerie in your CLASSPATH project. it may be wort
to create new workspace and bran new project in eclipse and see how
things work in such case.
best,
alek
Dear Aleksander
Hi!
I bypassed the problem of the missing XmlPullParserFactory class by
creating the relevant packages and creating classes within them as
needed so that I now have the following projects/classes:
- org.xmlpull.v1
- XmlPullParser.java
- XmlPullParserException
- XmlPullParserFactory
- XmlSerializer
- org.xmlpull.mxp1
- MxParser.java
But now, when I run the following statement it throws an exception on
the following line of code
XmlPullParserFactory factory =
XmlPullParserFactory.newInstance(System.getProperty(XmlPullParserFactory.PROPERT\
Y_NAME),
null);
I presume that it is because I am not properly setting the class to
MxParser.java - if that is the problem, can you please tell me how to
do that? I did look at the
Class XmlPullParserFactory documentation, and did see the reference to
Thread.getContextClassLoader().getClass() but I don't know how to get
that to work.
Thanks/Phil
At 20:36 2007-04-01, you wrote:
>Aleksander Slominski wrote:
> > Phil Troy wrote:
> >
> >> Hi!
> >>
> >> I am using Eclipse, and have added xpp3_min-1.1.4c.jar to be an
> >> external jar for my current Eclipse project. I have added imports for
> >> xmlPullParser as follows:
> >>
> >> import org.xmlpull.v1.XmlPullParser;
> >> import org.xmlpull.v1.XmlPullParserException;
> >> import org.xmlpull.v1.XmlPullParserFactory;
> >>
> >> I build my project in Eclipse and get the following error "the
> >> import org.xmlpull.v1.XmlPullParserFactory cannot be resolved.
> >>
> >> (I am guessing that XmlPullParserFactory is not in the jar mentioned
> >> above.)
> >>
> >> How do I fix this problem?
> >>
> >>
> > min version (xpp3_min-1.1.4c.jar) is minimal and it does not have parser
> > factory - you have two options:
> > 1. create parser directly using its public constructor (new MXParser()
> > should work)
> >
> > 2. download standard xpp3 jar version
> >
>
<http://www.extreme.indiana.edu/dist/java-repository/xpp3/jars/xpp3-1.1.4c.jar>h\
ttp://www.extreme.indiana.edu/dist/java-repository/xpp3/jars/xpp3-1.1.4c.jar
> > and then you can use XmlPullParserFactory
> >
>correction - i just checked [1] and you should be fine with min version
>(you need standard for serializer and faster parser) and [1] has
>XmlPullParserFactory so maybe you need to double check your jar file you
>use in Eclipse (and download it again if necessary) - also check if your
>eclipse project classpath settings do nto have duplicate of xpp3/xmlpull
>interfaces/classes
>
>HTH,
>
>alek
>[1]
><http://www.extreme.indiana.edu/dist/java-repository/xpp3/jars/xpp3_min-1.1.4c.\
jar>http://www.extreme.indiana.edu/dist/java-repository/xpp3/jars/xpp3_min-1.1.4\
c.jar
>
>
Philip M. Troy, Ph.D.,
Decision Support Systems Analyst
PhilTroy@...
www.PhilTroy.com
THANKS/Phil
At 20:29 2007-04-01, you wrote:
>Phil Troy wrote:
> > Hi!
> >
> > I am using Eclipse, and have added xpp3_min-1.1.4c.jar to be an
> > external jar for my current Eclipse project. I have added imports for
> > xmlPullParser as follows:
> >
> > import org.xmlpull.v1.XmlPullParser;
> > import org.xmlpull.v1.XmlPullParserException;
> > import org.xmlpull.v1.XmlPullParserFactory;
> >
> > I build my project in Eclipse and get the following error "the
> > import org.xmlpull.v1.XmlPullParserFactory cannot be resolved.
> >
> > (I am guessing that XmlPullParserFactory is not in the jar mentioned
> > above.)
> >
> > How do I fix this problem?
> >
>min version (xpp3_min-1.1.4c.jar) is minimal and it does not have parser
>factory - you have two options:
>1. create parser directly using its public constructor (new MXParser()
>should work)
>2. download standard xpp3 jar version
><http://www.extreme.indiana.edu/dist/java-repository/xpp3/jars/xpp3-1.1.4c.jar>\
http://www.extreme.indiana.edu/dist/java-repository/xpp3/jars/xpp3-1.1.4c.jar
>and then you can use XmlPullParserFactory
>
>HTH,
>
>alek
> > Philip M. Troy, Ph.D.,
> > Decision Support Systems Analyst
> > <mailto:PhilTroy%40Mail.com>PhilTroy@...
> > www.PhilTroy.com
> >
> >
> >
> >
> >
> >
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
>
>--
>The best way to predict the future is to invent it - Alan Kay
>
>
Philip M. Troy, Ph.D.,
Decision Support Systems Analyst
PhilTroy@...
www.PhilTroy.com
Aleksander Slominski wrote:
> Phil Troy wrote:
>
>> Hi!
>>
>> I am using Eclipse, and have added xpp3_min-1.1.4c.jar to be an
>> external jar for my current Eclipse project. I have added imports for
>> xmlPullParser as follows:
>>
>> import org.xmlpull.v1.XmlPullParser;
>> import org.xmlpull.v1.XmlPullParserException;
>> import org.xmlpull.v1.XmlPullParserFactory;
>>
>> I build my project in Eclipse and get the following error "the
>> import org.xmlpull.v1.XmlPullParserFactory cannot be resolved.
>>
>> (I am guessing that XmlPullParserFactory is not in the jar mentioned
>> above.)
>>
>> How do I fix this problem?
>>
>>
> min version (xpp3_min-1.1.4c.jar) is minimal and it does not have parser
> factory - you have two options:
> 1. create parser directly using its public constructor (new MXParser()
> should work)
>
> 2. download standard xpp3 jar version
> http://www.extreme.indiana.edu/dist/java-repository/xpp3/jars/xpp3-1.1.4c.jar
> and then you can use XmlPullParserFactory
>
correction - i just checked [1] and you should be fine with min version
(you need standard for serializer and faster parser) and [1] has
XmlPullParserFactory so maybe you need to double check your jar file you
use in Eclipse (and download it again if necessary) - also check if your
eclipse project classpath settings do nto have duplicate of xpp3/xmlpull
interfaces/classes
HTH,
alek
[1]
http://www.extreme.indiana.edu/dist/java-repository/xpp3/jars/xpp3_min-1.1.4c.ja\
r
Phil Troy wrote:
> Hi!
>
> I am using Eclipse, and have added xpp3_min-1.1.4c.jar to be an
> external jar for my current Eclipse project. I have added imports for
> xmlPullParser as follows:
>
> import org.xmlpull.v1.XmlPullParser;
> import org.xmlpull.v1.XmlPullParserException;
> import org.xmlpull.v1.XmlPullParserFactory;
>
> I build my project in Eclipse and get the following error "the
> import org.xmlpull.v1.XmlPullParserFactory cannot be resolved.
>
> (I am guessing that XmlPullParserFactory is not in the jar mentioned
> above.)
>
> How do I fix this problem?
>
min version (xpp3_min-1.1.4c.jar) is minimal and it does not have parser
factory - you have two options:
1. create parser directly using its public constructor (new MXParser()
should work)
2. download standard xpp3 jar version
http://www.extreme.indiana.edu/dist/java-repository/xpp3/jars/xpp3-1.1.4c.jar
and then you can use XmlPullParserFactory
HTH,
alek
> Philip M. Troy, Ph.D.,
> Decision Support Systems Analyst
> PhilTroy@...
> www.PhilTroy.com
>
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
--
The best way to predict the future is to invent it - Alan Kay
Hi!
I am using Eclipse, and have added xpp3_min-1.1.4c.jar to be an
external jar for my current Eclipse project. I have added imports for
xmlPullParser as follows:
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
I build my project in Eclipse and get the following error "the
import org.xmlpull.v1.XmlPullParserFactory cannot be resolved.
(I am guessing that XmlPullParserFactory is not in the jar mentioned
above.)
How do I fix this problem?
Thanks/Phil
Philip M. Troy, Ph.D.,
Decision Support Systems Analyst
PhilTroy@...
www.PhilTroy.com
hi,
it is some time we did any modification to XmlPull API 1.1 (it is
remarkably stable) but there are few minor issues and improvements
recorded over years (and J2ME devices get bigger memory nowadays ...) so
it looks like good time for incremental release i.e. 1.2
based on list of issues and improvements (RFE) in bugzilla two stands out:
1) http://www.extreme.indiana.edu/bugzilla/show_bug.cgi?id=167
skipSubTree() looks like a very useful method to have implemented in
parser (skipping can be fast) - that would add to XmlPullParser method:
/**
* Skip sub tree on which the parser is currently positioned on.
* <br>NOTE: parser must be on START_TAG and when function returns
* parser will be positioned on matching END_TAG
*
* This method is typically optimized by parser but the its logic
should follow this:
* <code>
* require(XmlPullParser.START_TAG, null, null);
* int level = 1;
* while(level > 0) {
* int eventType = next();
* if(eventType == XmlPullParser.END_TAG) {
* --level;
* } else if(eventType == XmlPullParser.START_TAG) {
* ++level;
* }
* }
* </code>
*/
public void skipSubTree() throws XmlPullParserException, IOException;
2) http://www.extreme.indiana.edu/bugzilla/show_bug.cgi?id=240
this is long standing issue related to how setPrefix() works and how it
should be working more like xmlns:pref='...' (so digital signatures code
works well) - that would add to XmlSerializer three new methods with
prefix as an argument:
public XmlSerializer startTag (String prefix, String namespace, String
name)
public XmlSerializer endTag (String prefix, String namespace, String name)
public XmlSerializer attribute (String prefix, String namespace, String
name, String value)
if there are any other issues/improvements/etc please let us know (send
email to xmlpull-dev and log the issues in bugzilla)
both XPP3/5 and kXML2 plan to implement soon XmlPull API 1.2
thanks,
Alek Slominski (& Stefan Haustein)
XML Visualization, Analytics, and High Performance Processing
Major Themes
Visualization fosters comprehension
Analytics fosters insight
High performance processing requires performant
architectures and new XML APIs
History of HTML and XML Visualization
Visualization and Comprehension
XML Visualization Demos
History of HTML and XML Analytics
Analytics and Insight
XML Analytics Demos
Understanding High Performance XML Processing
Using Visualization and Analytics technologies to help define new
XML architectures and APIs
New Architectures for XML Document Loading
New XML Access/Search APIs: Introducing the "Exclude Others-style"
API
New Architecture for XML Document Serialization
The requirement for XML transactions in applications: Implementing
Spheres of Control
Group Application #1: Using Visualization and Analytics to help
build a Web 2.0 Mashup
Group Application #2: Using the Exclude-Others API to efficiently
Of particular importance to the XPP community will be the discussion and demos of new XML processing architectures and APIs, many of which enhance the core XPP technology.
public class PullParserTest { public static void main(String[] args) { File file; FileReader fileReader; DOM2XmlPullBuilder pullBuilder;
if (args.length < 1) { System.out.println("Enter the name of the XML file on the command line."); System.exit(0); } try { file = new File(args[0]); fileReader = new FileReader(file);
pullBuilder = new DOM2XmlPullBuilder(); pullBuilder.parse(fileReader); } catch (Exception ex) { ex.printStackTrace(); } } }
Nitin wrote:
> Hi,
> I have a requirement wherein I have to process a compressed file
> containing multiple xml files (lets say AllXMLs.tar.gz)....I have to
> parse all the XML files without uncompressing them.
> I can use the classes available in java.util.zip package to create
> InputStream for the contents of the XML files..But can the XML Pull
> parser process it...??
>
> Currently when I am passing the Input Stream to the Parser, I get
> the following exception:
> Exception in thread "main" org.gjt.xpp.XmlPullParserException: only
> whitespace content allowed outside root element at
> ine 2 and column 3 seen "...<?xml version="1.0" encoding="ISO-8859-
> 1"?>\n"...
that would indicate that there is something <?xml version="1.0"
encoding="ISO-8859-1"?> in your input after decompressin - if it is
tar.gz it is not enough to decompress you need also to extract each file
from tar archive.
to verify try to gzip an XML file and then parse - i bet it would work ;-)
best,
alek
> (parser state CONTENT)
> at org.gjt.xpp.impl.pullparser.PullParser.next
> (PullParser.java:429)
> at ZipParser.readGZIPFile(ZipParser.java:62)
> at ZipParser.main(ZipParser.java:17)
>
>
> My function looks something like this:
> private static void readGZIPFile(String fileName) throws Exception
> {
> // use BufferedReader to get one line at a time
> BufferedReader gzipReader = null;
> XmlPullParserFactory factory =
> XmlPullParserFactory.newInstance();
> XmlPullParser pp = factory.newPullParser();
> pp.setAllowedMixedContent(true);
>
> try
> {
> // simple loop to dump the contents to the
> console
> gzipReader = new BufferedReader( new
> InputStreamReader( new GZIPInputStream(new FileInputStream
> (fileName))));
> while (gzipReader.ready())
> {
> pp.setInput(gzipReader);
>
> // input could be also taken from
> String directly:
> //pp.setInput(data.toCharArray());
>
> // 4. parsing
>
> //declare variables used during
> parsing
> XmlStartTag stag =
> factory.newStartTag();
> XmlEndTag etag = factory.newEndTag();
>
>
> byte type; // received event type
> byte prevType; // previous event
> type
>
> type = prevType = pp.next();
> if(type == XmlPullParser.START_TAG) {
> pp.readStartTag(stag);
> //System.err.println("read
> start tag "+stag);
> if(! "test".equals
> (stag.getLocalName())) {
> throw new
> RuntimeException("bulk data must start with test not "
>
> +stag.getLocalName()
> +pp.getPosDesc());
> }
> } else {
> throw new RuntimeException
> ("unexpected end of data "+pp.getPosDesc());
> }
>
> // start parsing loop
> for(;;) {
> type = pp.next();
> if(type ==
> XmlPullParser.START_TAG) {
> pp.readStartTag
> (stag);
> //System.err.println
> ("read start tag "+stag);
> type = pp.next();
> String content = "";
> if(type ==
> XmlPullParser.CONTENT) {
> content =
> pp.readContent();
>
> //System.err.println("read content="+content);
> while(type !
> = XmlPullParser.END_TAG) {
> try {
>
> type = pp.next();
> }
> catch(Exception e){
>
> System.err.println("ERROR recovering from "+e);
>
> // give it a second chance
>
> //type = pp.next();
>
> type = pp.getEventType();
> }
> }
> }
> if(type !=
> XmlPullParser.END_TAG) {
> throw new
> RuntimeException("expected end tag not "+pp.getPosDesc());
> }
> System.err.println
> ("LOAD tag="+stag.getLocalName()+" data='"+content+"'");
> } else if(type ==
> XmlPullParser.END_TAG) {
> break;
> } else if(type ==
> XmlPullParser.END_DOCUMENT) {
> throw new
> RuntimeException("unexpected end of data "+pp.getPosDesc());
> } else {
> throw new
> RuntimeException("unknown event type: "+type);
> }
> }
> }
> gzipReader.close();
> }
> catch (FileNotFoundException fnfe)
> {
> System.out.println("The file was not
> found: " + fnfe.getMessage());
> }
> catch (IOException ioe)
> {
> System.out.println("An IOException
> occurred: " + ioe.getMessage());
> }
> finally
> {
> if (gzipReader != null)
> {
> try
> {
> gzipReader.close();
> }
> catch (IOException ioe)
> {
> }
> }
> }
> }
>
> Can you please advise
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
--
The best way to predict the future is to invent it - Alan Kay
Hi,
I have a requirement wherein I have to process a compressed file
containing multiple xml files (lets say AllXMLs.tar.gz)....I have to
parse all the XML files without uncompressing them.
I can use the classes available in java.util.zip package to create
InputStream for the contents of the XML files..But can the XML Pull
parser process it...??
Currently when I am passing the Input Stream to the Parser, I get
the following exception:
Exception in thread "main" org.gjt.xpp.XmlPullParserException: only
whitespace content allowed outside root element at
ine 2 and column 3 seen "...<?xml version="1.0" encoding="ISO-8859-
1"?>\n"... (parser state CONTENT)
at org.gjt.xpp.impl.pullparser.PullParser.next
(PullParser.java:429)
at ZipParser.readGZIPFile(ZipParser.java:62)
at ZipParser.main(ZipParser.java:17)
My function looks something like this:
private static void readGZIPFile(String fileName) throws Exception
{
// use BufferedReader to get one line at a time
BufferedReader gzipReader = null;
XmlPullParserFactory factory =
XmlPullParserFactory.newInstance();
XmlPullParser pp = factory.newPullParser();
pp.setAllowedMixedContent(true);
try
{
// simple loop to dump the contents to the
console
gzipReader = new BufferedReader( new
InputStreamReader( new GZIPInputStream(new FileInputStream
(fileName))));
while (gzipReader.ready())
{
pp.setInput(gzipReader);
// input could be also taken from
String directly:
//pp.setInput(data.toCharArray());
// 4. parsing
//declare variables used during
parsing
XmlStartTag stag =
factory.newStartTag();
XmlEndTag etag = factory.newEndTag();
byte type; // received event type
byte prevType; // previous event
type
type = prevType = pp.next();
if(type == XmlPullParser.START_TAG) {
pp.readStartTag(stag);
//System.err.println("read
start tag "+stag);
if(! "test".equals
(stag.getLocalName())) {
throw new
RuntimeException("bulk data must start with test not "
+stag.getLocalName()
+pp.getPosDesc());
}
} else {
throw new RuntimeException
("unexpected end of data "+pp.getPosDesc());
}
// start parsing loop
for(;;) {
type = pp.next();
if(type ==
XmlPullParser.START_TAG) {
pp.readStartTag
(stag);
//System.err.println
("read start tag "+stag);
type = pp.next();
String content = "";
if(type ==
XmlPullParser.CONTENT) {
content =
pp.readContent();
//System.err.println("read content="+content);
while(type !
= XmlPullParser.END_TAG) {
try {
type = pp.next();
}
catch(Exception e){
System.err.println("ERROR recovering from "+e);
// give it a second chance
//type = pp.next();
type = pp.getEventType();
}
}
}
if(type !=
XmlPullParser.END_TAG) {
throw new
RuntimeException("expected end tag not "+pp.getPosDesc());
}
System.err.println
("LOAD tag="+stag.getLocalName()+" data='"+content+"'");
} else if(type ==
XmlPullParser.END_TAG) {
break;
} else if(type ==
XmlPullParser.END_DOCUMENT) {
throw new
RuntimeException("unexpected end of data "+pp.getPosDesc());
} else {
throw new
RuntimeException("unknown event type: "+type);
}
}
}
gzipReader.close();
}
catch (FileNotFoundException fnfe)
{
System.out.println("The file was not
found: " + fnfe.getMessage());
}
catch (IOException ioe)
{
System.out.println("An IOException
occurred: " + ioe.getMessage());
}
finally
{
if (gzipReader != null)
{
try
{
gzipReader.close();
}
catch (IOException ioe)
{
}
}
}
}
Can you please advise