1
    //Initialize soap request 

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

    //Use this to add parameters
    request.addProperty("agentcode",agentCode);
    request.addProperty("pincode",agentCodePin);
    request.addProperty("appversion",appversion);
    request.addProperty("deviceid",deviceid);
    request.addProperty("latitude",latitude);
    request.addProperty("longitude",longitude);

  //Declare the version of the SOAP request
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

    envelope.setOutputSoapObject(request);

    envelope.dotNet = true;

    try {

        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

        //this is the actual part that will call the web service
        androidHttpTransport.call(SOAP_ACTION, envelope);

        // Get the SoapResult from the envelope body.
        SoapObject result = (SoapObject)envelope.bodyIn;


        if(result != null)
        {

             DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
             factory.setNamespaceAware(true);

             DocumentBuilder builder = factory.newDocumentBuilder();

             InputSource is = new InputSource();
             is.setCharacterStream(new StringReader( result.toString()));

             org.w3c.dom.Document doc = builder.parse(is);

             doc.getDocumentElement().normalize();
            //Get Node List
             NodeList nlist = doc.getElementsByTagName("paypoint");
            //Get node
             Node nNode = (Node) nlist.item(0);

            if (nNode.getType(0) == Node.ELEMENT)
            {
                //get element
                Element elt = (Element) nNode; 

                // Get token
                this.token = elt.getElementsByTagName("token").item(0).getTextContent();
                // Get flag
                this.flag = elt.getElementsByTagName("statusCode").item(0).getTextContent();
                // Get agent name
                this.agentName = elt.getElementsByTagName("fullname").item(0).getTextContent();
            }

            }
          } catch (Exception e)
          {
                throw e;
          }

        return this.flag;

この行で問題が発生しています: is.setCharacterStream(new StringReader( result.toString()));

エラー: PI must not start with xml (部分: unknown xml@1:30 in java.io.stringReader@40579f48)

私の Xml ファイルは次のようになります。

<string xmlns="http://tempuri.org/">
<?xml version="1.0" encoding="utf-16"?><paypoint> <token>PkSMTTulAndNmM9R4Vmi+QRWtChW/Xs61sPERoTpB5eEgRfrQKUi6r2rqLQNusvJpVJ1oZBc8Z0=</token>   <statusCode>1</statusCode><statusText>VALID USER</statusText><fullname>Dao    Lacina</fullname><walletbalance>2000.00</walletbalance></paypoint>

どんな助けでも

4

4 に答える 4

4

<?xml version="1.0" encoding="utf-16"?>XML ドキュメントの最初の行である必要があります。代わりに試していただけますか:

<?xml version="1.0" encoding="utf-16" ?>
<string xmlns="http://tempuri.org/">
<paypoint> 
<token>PkSMTTulAndNmM9R4Vmi+QRWtChW/Xs61sPERoTpB5eEgRfrQKUi6r2rqLQNusvJpVJ1oZBc8Z0=</token>   
<statusCode>1</statusCode>
<statusText>VALID USER</statusText>
<fullname>Dao    Lacina</fullname>
<walletbalance>2000.00</walletbalance>
</paypoint>
</string>
于 2013-05-15T13:13:38.540 に答える
1

これは、日食のアンドロイドで私に起こっていました...ファイルの先頭から3バイトのutf-8 bomを削除することで解決しました。

http://en.wikipedia.org/wiki/Byte_order_mark#UTF-8

于 2015-04-02T01:47:19.060 に答える
1

あなたの XML は ではありませんwell-formed。最初の行はする必要があります

<?xml version="1.0" encoding="utf-16"?>

だからあなたのXMLはで始まるべきです

<?xml version="1.0" encoding="utf-16"?>
<string xmlns="http://tempuri.org/">

整形式のドキュメントに関する Wiki を参照してください

于 2013-05-15T13:15:13.183 に答える
0

私も同じ問題を抱えていましたが、それは適切に形成されていないXMLドキュメントのせいではないことがわかりました.クライアント側へのデータ...私のサーバー側のコードはこれです:

DataOutputStream dos = new DataOutputStream((OutputStream) response.getOutputStream());

しかし、私のクライアント側のコードは次のとおりです。

InputStream is =(InputStream) httpConnection.openDataInputStream();

最後に、ストリームを互いに一致するように変更し、問題も解決しました...ストリームが同じInputStreamに継承されていても、それらのストリームが異なる場合になぜそれが起こるのかまだわかりません

(私はこれを J2ME SDK 3.0.5 に使用しました)

于 2013-08-11T17:44:24.240 に答える