Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
crazyllama
Posts: 21
Registered: ‎03-08-2009
My Device: Not Specified
Accepted Solution

XML parsing "&"

I am using the w3c dom parser and noticed that the getNodeValue() method on a Node object does not seem to be able to parse & correctly. The xml used is as follows:

 

<name>name with ampersand &amp; and other stuff</name> 

 

The returned result on calling getNodeValue() was: "name with ampersand "

 

It is truncating the string on seeing the "&". Is anyone else seeing this problem? If so, do you know a fix for it?

 

Thanks. 

Please use plain text.
Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: XML parsing "&amp;"

I had this also - I wound up writing a utility class to "scrub" the HTML entities from the XML and convert them to unicode.

 

Example: &amp; becomes &#38;

 

There is probably a better way, but I couldn't find it!

 

Please use plain text.
Developer
pwerry
Posts: 177
Registered: ‎01-21-2009
My Device: 9900

Re: XML parsing "&amp;"

Try calling setCoalescing( true ) on your DocumentBuilderFactory
Please use plain text.
Developer
crazyllama
Posts: 21
Registered: ‎03-08-2009
My Device: Not Specified

Re: XML parsing "&amp;"

Thanks,

 

That worked !

Please use plain text.