2017-04-11 7 views
2

ksoap을 사용하여 비누에 접두사 태그를 추가하는 방법은 무엇입니까?SOAP 요청에 XML 접두어 추가

<v:Envelope xmlns:cnx="http://db.hutt.com" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/"> 
     <v:Header> 
      <authentication xmlns:n0="http://db.hutt.com"> 
       <userName>tutt</userName> 
       <password>[email protected]</password> 
      </authentication> 
     </v:Header> 
     <v:Body> 
      <cnx:get_tt xmlns=""> 
       <ttid>1</ttid> 
      </cnx:get_tt> 
     </v:Body> 
    </v:Envelope> 
+0

귀하의 요청을 수정 한 후에도 귀하의 요청은 동일하게 보입니다. 무엇을 바꾸시겠습니까? – KarelHusa

+1

ttid 요소는 아마도 http://sdm.hott.com 네임 스페이스에 속하지 않습니다. public SoapObject addProperty (String namespace, String name, Object value) 메소드와 함께 ttid 요소를 추가하고 네임 스페이스를 빈 문자열로 설정할 수 있습니다. – KarelHusa

+0

@KarelHusa 질문을 편집했습니다. 본문의 요청에 태그가 있어야하는 동안 헤더에 태그가 없어야합니다. – kinkajou

답변

0

그래서, 혹시 당신이 예를 태그하는 중요하지 않습니다 CNX = "http://db.hutt.com":에 xmlns : 내가 추가 할 V : 봉투 또는 soapenv : 봉투입니다. soapserver가 자동으로 구문 분석합니다. 또한 xml envelop에 접두어를 추가하려면 클래스를 확장해야합니다. SoapSerializationEnvelope.

import org.ksoap2.SoapEnvelope; 
import org.ksoap2.serialization.SoapSerializationEnvelope; 
import org.xmlpull.v1.XmlSerializer; 

import java.io.IOException; 

/** 
* Created by suamatya on 4/11/2017. 
*/ 

public class CustomSoapSerializationEnvelope extends SoapSerializationEnvelope { 

    CustomSoapSerializationEnvelope(int version){ 
     super(version); 
    } 

    @Override 
    public void write(XmlSerializer writer) throws IOException { 
     writer.setPrefix("i", xsi); 
     writer.setPrefix("d", xsd); 
     writer.setPrefix("c", enc); 
     writer.setPrefix("v", env); 
     writer.setPrefix("db","http://db.hott.com"); 
     writer.startTag(env, "Envelope"); 
     writer.startTag(env, "Header"); 
     writeHeader(writer); 
     writer.endTag(env, "Header"); 
     writer.startTag(env, "Body"); 
     writeBody(writer); 
     writer.endTag(env, "Body"); 
     writer.endTag(env, "Envelope"); 
    } 
}