aspose file tools*
The moose likes XML and Related Technologies and the fly likes Not able to read the big string value in StAX Parsing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Not able to read the big string value in StAX Parsing" Watch "Not able to read the big string value in StAX Parsing" New topic
Author

Not able to read the big string value in StAX Parsing

piyush ranjan
Greenhorn

Joined: Mar 13, 2012
Posts: 2
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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Mar 13, 2012
Posts: 2
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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Not able to read the big string value in StAX Parsing