使用空标记解析SoapObject XML

时间:2013-02-22 14:20:44

标签: xml parsing soap envelope

大家好我从webservice解析Soaobject xml然后xml标签不是空的,一切都好,但是它们是空的例子“<barcode></barcode>”它使string-anyType {}。并在我的列表中显示!  :(我该怎么做才能从列表中删除这个单词“anyType {}”,它显示什么或我写的东西?   envelope.implicitTypes = false; ---&GT;这不起作用....仍然得到任何类型{} ... 这是我的代码:

String [] xmlElements = {“Id”,“name”,“Unit”,“Cost”,“description”,“barcode”};

  SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
      envelope.dotNet=true;
      envelope.setOutputSoapObject(request);

      androidHttpTransport.call(SOAP_ACTION, envelope); 

      ArrayList<HashMap<String, String>> Tags = new ArrayList<HashMap<String, String>>();

      if ( xmlelements==null&& KEY_RAKTINIS==null){
          Object soapObj = (SoapObject)envelope.getResponse();
          soapObj = ((SoapObject) soapObj).getProperty(KEY_PATVIRTINIMAS);
         Toast.makeText(getActivity().getBaseContext(), soapObj.toString(), Toast.LENGTH_SHORT).show();

      }else {
            SoapObject soapObj = (SoapObject)envelope.getResponse();
   soapObj = (SoapObject) soapObj.getProperty(KEY_RAKTINIS);// su situo ieinu i butent customers punkta

      for (int  j = 0; j < soapObj.getPropertyCount(); j++) {
        SoapObject   soapObjMenu = (SoapObject) soapObj.getProperty(j);

    for (int  i = 0; i <1; i++) {
              HashMap<String, String> map = new HashMap<String, String>(); 
                    for( i=0; i < xmlelements.length;i++){

           if (soapObjMenu.getProperty(xmlelements[i])!="") { 
               map.put(xmlelements[i], (soapObjMenu.getProperty(xmlelements[i]).toString()));
               Log.v(xmlelements[i], "sitas");}
              }

                    Tags.add(map);
                                }}

<Items>

<Item>

<Id>1000</Id>

<name>LCD Television HD Black 42 inches</name>

<Unit>ea</Unit>

<Cost>2000.00</Cost>

<description>Simple SKU</description>

<barcode></barcode>

</Item>

<Item>

<Id>1001</Id>

<name>LCD Television Model 01</name>

<Unit>ea</Unit>

<Cost>4015.00</Cost>

<description></description>

<barcode></barcode>

</Item>

<Item>

<Id>1003</Id>

<name>Plasma Television Model 01</name>

<Unit>ea</Unit>

<Cost>4020.00</Cost>

<description></description>

<barcode></barcode>

</Item>

`

1 个答案:

答案 0 :(得分:0)

我解决了问题,只需使用.equals(“that string”)

示例

HashMap<String, String> map = new HashMap<String, String>(); 
                    for( i=0; i < xmlelements.length;i++){


                        if (!soapObjMenu.getProperty(xmlelements[i]).toString().equals("anyType{}")){ // use when tag is empty...
               map.put(xmlelements[i], (soapObjMenu.getProperty(xmlelements[i]).toString()));}else{ map.put(xmlelements[i], (" "));}
                            }
                    Tags.add(map);
                                }}}

P.S。如果你不在字符串中使用空间就会出现问题,那么你就可以通过这个map.put(xmlelements [i],(“”))从你的应用程序发送给服务了所以必须只为空间改变它;)

没有人帮助,但我希望它对某人有帮助;)