2

I am sending a string from .net service to java class but in java , I am getting org.xml.sax.SAXParseException: Character reference "&#x0" is an invalid XML character.

Please help me in solving this. Thanks in advance.

1
  • What encoding does the document use, and does it declare it? What is the content of the string? Are you deliberately trying to include U+0000? Commented Jul 29, 2013 at 14:54

2 Answers 2

1

In C or C++ strings are terminated by the null (or '\0'). In C# a string can contain a null, but often these come from a C/C++ function.

You can get rid of the null in the .net String with

s = s.Replace("\0", "");  // just removes the null

or

int pos = s.IndexOf('\0');  
if (pos >= 0)
    s = s.Substring(0, pos); // removes the null and the rest of the string

depending on what is the reason for the null in the string.

Sign up to request clarification or add additional context in comments.

6 Comments

Hi Roland, Thanks for your reply. I have removed null character from the string but output is not stable. I am getting illegal argument exception some times and sometimes I am getting correct output. Please help me in solving this.
@sulthana Can you give some more information in which circumstances the exception occures and when does it work? And where the exception occures (java or .net part, which line/command )...
hi Roland, The exception is coming in java.While returning the string in JAVA class the exception is coming. Here is the exception **SEVERE: Servlet.service() for servlet AppService threw exception java.lang.IllegalArgumentException: The char '0x0' after 'return ' is not a valid XML character.
looks like there is still a '\0' in one of the arguments. can you asure that there are no more '\0' in all of the arguments?
@sulthana is this question related to the other questions link from you? Then you should first solve the connection/proxy problem, as this has nothing to do with passing back a string from .net.
|
0

Some invalid characters will cause Exception while parsing XML, official defined those three scopes of invalid characters:

0x00 - 0x08  
0x0b - 0x0c  
0x0e - 0x1f

So you may filter them before parsing XML content.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.