File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not able to read the big string value in StAX Parsing

 
piyush ranjan
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am using the StAX parsing to read the XML.
In my case,the xml contains one attribute as <description>......</description>.
But,if the size of the value for description tag is more(eg: 300 lines and each line having around 8000 characters)the StAX is not able to read the whole value.
for getting the value I am using getText() method of stream reader
It will read only 3-4 lines.My question is:
1)how to read the whole value?
2)what is the max. size StAX will read for an attribute?
 
Paul Clapham
Sheriff
Pie
Posts: 20184
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume that if you call getText() again you will get some more text from that text node. Or perhaps you could call getTextElement() to get the whole text node, or use a version of the code which appears in the API documentation for getTextElement().

You didn't consider doing a simple debugging exercise like reading through the document and outputting the list of events that Stax saw? There's a lot to be said for trying things to see what happens. Usually it's more educational than asking a single question on a forum.
 
piyush ranjan
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul,
Thanks for the comment.
Now ,I am getting the value by using getText() method after every event and concatinating the value.Like

while(stre.hasNext())
{
int event = stre.next();
while(event != XMLStreamConstants.END_ELEMENT){
if(event==XMLStreamConstants.CHARACTERS) {
description = description + stre.getText();
event = stre.next();
}
}

return description;
}
 
Paul Clapham
Sheriff
Pie
Posts: 20184
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's good. Just one minor thing: if you're going to be doing a lot of concatenating to build up the big string, you might consider using a StringBuilder to do that. It's more resource-efficient, in terms of the number of temporary String objects you're creating.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic