Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

& characters is not getting with stax parser

 
yatin baraiya
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
& by itself is dangerous.

Try & and see what happens ;)

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

WP
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic