开发者

xml parsing for a single string that contains spaces

My Android app is calling .NET web method and it returns a single string. I am us开发者_JS百科ing saxparser to parse a single string like:

<string xmlns="http://tempuri.org/">LOCAL NT AUTHORITY\NTLM Authentication Not in role Administrators</string>

and characters() function in my data handler:

        public void characters(char ch[], int start, int length) {
        String chars = new String(ch, start, length);
        Log.v("characters", chars);
        chars = chars.trim();

        if (_inItem) {
            _data = chars;
        }
    }

My problem is that when I test it with webserver 1, it works ok but with webserver 2 it returns empty string.

With webserver 1, I saw characters() function is being called just once and it returns the whole string "LOCAL NT AUTHORITY\NTLM Authentication Not in role Administrators". Perfect!

But with webserver 2, charaters() function is being called multiple times and it finally returns empty string..?

04-20 10:09:43.161: VERBOSE/characters(405): LOCAL
04-20 10:09:43.161: VERBOSE/characters(405): NT AUTHORITY\NTLM Authentication
04-20 10:09:43.161: VERBOSE/characters(405): Not in role Administrators
04-20 10:09:43.250: VERBOSE/endElement(405): string=0

Is it about handling spaces? What's happening here?

I ended up changing characters() function:

public void characters(char ch[], int start, int length) {
    String chars = new String(ch, start, length);

    if (_inItem) {
        _data += chars;
    }
}


This is how the sax interface is defined, there can be multiple calls to characters, its not expected that you'll get all the characters in a single element in one call. If you need the entire string in one piece, its up to your implementation to collect and concatenate them together.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜