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>";

在这里,当我尝试添加文本元素类型值必须由匹配的结束标记终止时,它会抛出空指针异常。我该如何处理。我希望以下部分抛出错误。问题在于“结束标签”。我该如何处理。

+ "<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;XML CDATAStackoverflow

于 2012-09-20T07:49:48.230 回答