0
"<?xml version=\"1.0\"?>"
                + "<methodResponse>"
                + "<fault>"
                + "<value>"
                + "<struct>"
                + "<member>"
                + "<name>faultCode</name>"
                + "<value>"
                + "<int>"
                + "-1"
                + "</int>"
                + "</value>"
                + "</member>"
                + "<member>"
                + "<name>faultString</name>"
                + "<value>"
                + "<string>"
                + "The element type value must be terminated by the matching end-tag </value>"
                + "</string>" + "</value>" + "</member>" + "</struct>"
                + "</value>" + "</fault>" + "</methodResponse>";

ここで、テキスト The element type value must be terminate by the matching end-tag を追加しようとすると、nullpointer 例外がスローされます。どうすればこれを処理できますか。次の部分でエラーが発生することを願っています。問題は「終了タグ」にあります。どうすればこれを処理できますか。

+ "<string>"
                    + "The element type value must be terminated by the matching end-tag </value>"
                    + "</string>" +
4

3 に答える 3

3

XML を自分で作成するのではなく、XML API を使用して、これを処理する必要があります。

</value>エスケープせずにテキストの一部として含めようとして、無効な XML を作成しています。そうあるべき&lt;/value>ですが、これを手動で修正するのではなく、XML の作成時に XML API を使用する必要があります。

(はにエスケープ> でき&gt;ますが、そうである必要はありません。)

于 2012-09-20T07:30:39.343 に答える
2

リテラルをエスケープする必要があります...

"The element type value must be terminated by the matching end-tag &lt;/value&gt;"
于 2012-09-20T07:30:42.447 に答える
0

XML文字列でCDATAを使用してみてください。XMLCDATAStackoverflow

于 2012-09-20T07:49:48.230 に答える