shabby
shabby

Reputation: 3222

Special characters Parsing error in xml dom in java

i am using org.w3c.dom in java to read an xml with the following function

try
        {
            cwNodes =  xmlDoc.getElementsByTagName("cw-page");
        }
        catch(Exception doe)
        {
            BusinessLogic.WriteLog("Exp msg: "+doe.getMessage());

        }

the xml is

<cw-page id='4545' num='1'>dlfdlkfsdf</cw-page>

it reads fine but when i pass the following xml

<cw-page id='4545' num='1'>dlfdlkfsdf&!@#%^*()</cw-page>

it doesnt read it, the exception essage is null as well, dont know what is wrong can anybody help, thanks

Upvotes: 0

Views: 1804

Answers (1)

Vineet Reynolds
Vineet Reynolds

Reputation: 76719

& cannot occur by itself in a XML document as it is used to start a XML entity reference. Therefore, your XML document must contain &amp; and not & if a parser has to parse its contents correctly and return & in the text content. & is not the only character that XML parsers will fail to parse incorrectly if they are present on their own; there are other characters that must be present as the predefined XML entities for parsing to occur correctly.

You should either correct the document, by using entity references or use CDATA sections to transport the special characters in the payload.

Upvotes: 4

Related Questions