別の xml 内の cdata タグ内で xml を解析することについて質問があります。検索しましたが、正確な問題が見つかりませんでした。例を投稿します:
<?xml version="1.0" encoding="UTF-8"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:CSResponse xmlns:ns2="http://webservices....../">
<RespuestaVentaPrepagoTituloCS1>
<ICallId>0</ICallId>
<IResultCode>1</IResultCode>
<SResulXML>
<![CDATA[null<?xml version="1.0" encoding="UTF-8"?>
<SS_prepagoCS version="0.1" fecha="2013-11-02T06:24:42" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation=".\SS_Pasdsd">
<TTPSearchResult value="1" desc="OK">
<TTPData xsi:nil="false">
<SerialNumber>56676543243234</SerialNumber>
....
しかし、私が受け取った応答は次のとおりです。
<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:CS1Response xmlns:ns2="http://webservices..../">
<RespuestaVentaPrepagoTituloCS1>
<ICallId>0</ICallId>
<IResultCode>1</IResultCode>
<SResulXML>null<?xml version="1.0" encoding="UTF-8"?><SS_prepagoCS version="0.1" fecha="2013-11-13T10:12:20" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation=".\SS_PrepagoCS_v0.1.xsd"> <TTPSearchResult value="1" desc="OK"> <TTPData xsi:nil="false">
また、saxパーサーがxmlタグを見つけることができないため、cdataのコンテンツを解析できません。誰か助けてくれませんか?
ありがとう
編集:コードを追加
私はリクエストをします:
String data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> " +
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:web=\"http://webservices.sayp.bit.crtm/\"> " +
" <soapenv:Header/> " +
" <soapenv:Body> " +
".... ";
String action = "";
HttpResponse res = sendRequest(serverV2 + method, data, action);
if (res.getStatusLine().getStatusCode() == 200) {
HttpEntity entity = res.getEntity();
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
CSHandler handler = new CSHandler();
parser.parse(entity.getContent()), handler);//entity.getContent
return handler.getResponse();
}
どこかで、次のコードの entity.getContent() を変更するとうまくいくはずだと読みましたが、結果は同じです。
HttpEntity entity = res.getEntity();
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
CSHandler handler = new CSHandler();
String xml=EntityUtils.toString(entity);
if (BuildConfig.DEBUG)
Log.i("XML", xml);
parser.parse(new InputSource(new String(xml)), handler);//entity.getContent
return handler.getResponse();
}
そして、CSHandler はタグを検索する通常の SAX パーサーですが、xml が html に変換されるため、タグを見つけることができません...