aspose file tools*
The moose likes XML and Related Technologies and the fly likes  & characters is not getting with stax parser 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 " & characters is not getting with stax parser" Watch " & characters is not getting with stax parser" New topic
Author

& characters is not getting with stax parser

yatin baraiya
Ranch Hand

Joined: Jul 17, 2012
Posts: 30
hi all

Following is my parsing code to parse the xml
snippets of my one of the xml parsing is <cell cellStyle="COLUMN_HEADER" cellType="1">Yatin & Baraiya</cell>

While parsing this string with following code snippets i get only "Yatin" value instead of the this value "Yatin & Baraiya".

The parser will skip my all the string character after "n".I think it will not read & this character.Now what should i do with below code to get full string characters.
Here i am using the stax parsing technique for parsing the xml.




Please anybody help me if you have any idea about this.

Thanks in Advance
Yatin Baraiya
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18907
    
    8

As I expected, it's your code that is ignoring that part of the text element. You only work with the first node following after a start-element node and ignore any others. So when the parser splits up a text node into more than one part -- as it is allowed to do -- you ignore all but the first part.

And by the way: I added code tags to your post. See how readable it looks now? Could you do that yourself in future?
William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 859

& by itself is dangerous.

Try & and see what happens ;)

If this is data, you may need to URL encode it.

WP
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18907
    
    8

No, it's just XML so you just need to escape the "&" properly as "&amp;" in the document. URL-encoding is pointless.

But if you don't do that then the parser will throw an exception. That isn't happening so that must mean that the XML is well-formed, which means the ampersand is correctly escaped.
yatin baraiya
Ranch Hand

Joined: Jul 17, 2012
Posts: 30
hy thanks to all

finally i had find the solution of my issue.

below is my changed code:


Regards
Yatin Baraiya
yatin baraiya
Ranch Hand

Joined: Jul 17, 2012
Posts: 30
Here i add the one more point for the said issue solution.Check the following code.
As per reading the API and getting the help from my team mate .,He said that

if the String is like :Yatin & Baraiya

then event.asCharacters() method will read chunk of characters from the string....[so it is read first Yatin then again the event.isCharacters() event fire and it will again read the reaming part of my string data]



then at the end it will read full string data,

thanks to my team leader.

Regards
Yatin Baraiya
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: &amp; characters is not getting with stax parser