Esempio n. 1
0
  public void testCompletedTasksAreCompletedWhenParsed() {
    XmlPullParser xmlParser = Xml.newPullParser();

    try {
      xmlParser.setInput(
          new StringReader(
              "<todo>"
                  + "<completed-at type=\"datetime\" nil=\"true\"/>"
                  + "<context-id type=\"integer\">3711</context-id>"
                  + "<created-at type=\"datetime\">2009-10-26T22:23:42+01:00</created-at>"
                  + "<description>Läs getting things done igen</description>"
                  + "<due type=\"datetime\" nil=\"true\"/>"
                  + "<id type=\"integer\">25076</id>"
                  + "<ip-address>90.232.35.15</ip-address>"
                  + "<notes>Primärt kring idéer och projekt</notes>"
                  + "<project-id type=\"integer\">4558</project-id>"
                  + "<recurring-todo-id type=\"integer\" nil=\"true\"/>"
                  + "<show-from type=\"datetime\" nil=\"true\"/>"
                  + "<state>completed</state>"
                  + "<updated-at type=\"datetime\">2010-02-03T10:37:19+01:00</updated-at>"
                  + "</todo>"));
    } catch (XmlPullParserException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    TaskParser parser = CreateSUT();
    Task task = parser.parseSingle(xmlParser).getResult();
    assertEquals("completed date isn't parsed correctly", true, task.isComplete());
  }
    @Override
    protected ArrayList<Photo> doInBackground(String... params) {
      try {
        baseUrl = params[0];
        setupParams();
        URL url = new URL(getEncodedUrl());
        HttpURLConnection con = (HttpURLConnection) url.openConnection();

        con.setRequestMethod("GET");
        con.connect();
        int statusCode = con.getResponseCode();
        if (statusCode == HttpURLConnection.HTTP_OK) {
          InputStream in = con.getInputStream();
          if (parserSwitch.isChecked()) return PhotoUtil.PhotoSaxParser.parsePhotos(in);
          else return PhotoUtil.PhotoPullParser.parsePhotos(in);
        }
      } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (SAXException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (XmlPullParserException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      return null;
    }
 @SuppressWarnings("unchecked")
 public synchronized T inflate(XmlPullParser parser, P root, boolean attachToRoot) {
   final AttributeSet attrs = Xml.asAttributeSet(parser);
   T result = (T) root;
   try {
     int type;
     while ((type = parser.next()) != XmlPullParser.START_TAG
         && type != XmlPullParser.END_DOCUMENT) {;
     }
     if (type != XmlPullParser.START_TAG) {
       throw new InflateException(parser.getPositionDescription() + ": No start tag found!");
     }
     T xmlRoot = createItemFromTag(parser, parser.getName(), attrs);
     result = (T) onMergeRoots(root, attachToRoot, (P) xmlRoot);
     rInflate(parser, result, attrs);
   } catch (InflateException e) {
     throw e;
   } catch (XmlPullParserException e) {
     InflateException ex = new InflateException(e.getMessage());
     ex.initCause(e);
     throw ex;
   } catch (IOException e) {
     InflateException ex =
         new InflateException(parser.getPositionDescription() + ": " + e.getMessage());
     ex.initCause(e);
     throw ex;
   }
   return result;
 }
 public List<ControllerConfiguration> parse(InputStream is) throws RobotCoreException {
   this.parser = null;
   try {
     XmlPullParserFactory newInstance = XmlPullParserFactory.newInstance();
     newInstance.setNamespaceAware(true);
     this.parser = newInstance.newPullParser();
     this.parser.setInput(is, null);
     int next = this.parser.getEventType();
     while (next != XmlPullParser.END_DOCUMENT) {
       ConfigurationType type = getConfigurationType(this.parser.getName());
       if (next == XmlPullParser.START_TAG) {
         if (type == ConfigurationType.MOTOR_CONTROLLER) {
           this.controllerConfigurations.add(parseMotorController(true));
         }
         if (type == ConfigurationType.SERVO_CONTROLLER) {
           this.controllerConfigurations.add(parseServoController(true));
         }
         if (type == ConfigurationType.LEGACY_MODULE_CONTROLLER) {
           this.controllerConfigurations.add(parseLegacyModuleController());
         }
         if (type == ConfigurationType.DEVICE_INTERFACE_MODULE) {
           this.controllerConfigurations.add(parseDeviceInterfaceModule());
         }
       }
       next = this.parser.next();
     }
   } catch (XmlPullParserException e) {
     RobotLog.w("XmlPullParserException");
     e.printStackTrace();
   } catch (IOException e2) {
     RobotLog.w("IOException");
     e2.printStackTrace();
   }
   return this.controllerConfigurations;
 }
Esempio n. 5
0
  // 二手市场的得到物品方法
  public Vector getWp_ws() {
    Vector result = null;
    String wsdlurl = "http://116.55.243.13:8080/Mywebservice/services/Object";
    String webmethod = "getob";
    String namespace = "http://test.com";
    String soapaction = namespace + webmethod;
    SoapObject request = new SoapObject(namespace, webmethod);
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.bodyOut = request;

    HttpTransportSE se = new HttpTransportSE(wsdlurl);
    try {
      se.call(soapaction, envelope);
      if (envelope.getResponse() != null) {
        result = (Vector) envelope.getResponse();
      }
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (XmlPullParserException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return result;
  }
Esempio n. 6
0
    @Override
    protected void onPostExecute(String result) {
      try {
        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        factory.setNamespaceAware(true);
        XmlPullParser xpp = factory.newPullParser();
        xpp.setInput(new StringReader(result));

        ArrayList<String> routeNumbers = XmlParser.getRouteNumbers(xpp);
        xpp.setInput(new StringReader(result)); // reset parser
        ArrayList<String> routeNames = XmlParser.getRouteNames(xpp);

        ArrayList<Map<String, String>> routes = new ArrayList<Map<String, String>>();
        for (int i = 0; i < routeNames.size(); i++) {
          Map<String, String> map = new HashMap<String, String>();
          map.put("routeNumber", routeNumbers.get(i));
          map.put("routeName", routeNames.get(i));
          routes.add(map);
        }

        listView = (ListView) getView().findViewById(R.id.busListView);
        adapter = new BusStopsAdapter(routes, getActivity());
        listView.setAdapter(adapter);
        listView.setTextFilterEnabled(true);
        listView.setOnItemClickListener(BusFragment.this);

        progressDialog.dismiss();
      } catch (XmlPullParserException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
 protected String doInBackground(Integer... params) {
   try {
     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
     SoapObject request = new SoapObject(Utilities.connection.NAMESPACE, "getuser");
     request.addProperty("Reg_id", params[0]);
     envelope.bodyOut = request;
     HttpTransportSE transport =
         new HttpTransportSE(
             Utilities.connection.url + Utilities.connection.x + Utilities.connection.exs);
     try {
       transport.call(
           Utilities.connection.NAMESPACE + Utilities.connection.SOAP_PREFIX + "getuser",
           envelope);
     } catch (IOException e) {
       e.printStackTrace();
       return "*";
     } catch (XmlPullParserException e) {
       e.printStackTrace();
       return "*";
     }
     result = envelope.getResponse().toString();
     if (envelope.bodyIn != null) {
       SoapPrimitive resultSOAP = (SoapPrimitive) ((SoapObject) envelope.bodyIn).getProperty(0);
       result = resultSOAP.toString();
     }
   } catch (Exception e) {
     e.printStackTrace();
     result = "*";
   }
   return result;
 }
Esempio n. 8
0
 // 得到公告内容
 public String get_content_ws(String id) {
   String wsdlurl = "http://116.55.243.13:8080/ViewManage/services/ViewManage";
   String webmethod = "getContent";
   String namespace = "http://ckpark.services.com";
   String soapaction = namespace + webmethod;
   SoapObject request = new SoapObject(namespace, webmethod);
   request.addProperty("id", id);
   SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
   envelope.bodyOut = request;
   HttpTransportSE se = new HttpTransportSE(wsdlurl);
   String result = null;
   try {
     se.call(soapaction, envelope);
     if (envelope.getResponse() != null) {
       result = envelope.getResponse().toString();
     }
   } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (XmlPullParserException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   return result;
 }
Esempio n. 9
0
 // 上传物品信息
 public boolean submit_goods_ws(String name, String price, String user, String tel) {
   String wsdlurl = "http://116.55.243.13:8080/Mywebservice/services/Object";
   String webmethod = "postnew";
   String namespace = "http://test.com";
   String soapaction = namespace + webmethod;
   SoapObject request = new SoapObject(namespace, webmethod);
   // String name,int price,String user,String tel
   request.addProperty("name", name);
   request.addProperty("price", price);
   request.addProperty("user", user);
   request.addProperty("tel", tel);
   SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
   envelope.bodyOut = request;
   HttpTransportSE se = new HttpTransportSE(wsdlurl);
   Vector result = new Vector();
   try {
     se.call(soapaction, envelope);
     if (envelope.getResponse() != null) {
       result = (Vector) envelope.getResponse();
       System.out.print(result);
     }
   } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (XmlPullParserException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   return true;
 }
Esempio n. 10
0
  private void loadConfiguration() {
    int id = getResources().getIdentifier("JustepApp", "xml", getPackageName());
    if (id == 0) {
      Logger.i("JustepAppLog", "JustepApp.xml missing. Ignoring...");
      return;
    }
    XmlResourceParser xml = getResources().getXml(id);
    int eventType = -1;
    while (eventType != XmlResourceParser.END_DOCUMENT) {
      if (eventType == XmlResourceParser.START_TAG) {
        String strNode = xml.getName();
        if (strNode.equals("preference")) {
          String name = xml.getAttributeValue(null, "name");
          String value = xml.getAttributeValue(null, "value");
          String readonlyString = xml.getAttributeValue(null, "readonly");

          boolean readonly = (readonlyString != null && readonlyString.equals("true"));

          Logger.i("JustepAppLog", "Found preference for %s", name);

          preferences.add(new PreferenceNode(name, value, readonly));
        }
      }
      try {
        eventType = xml.next();
      } catch (XmlPullParserException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
Esempio n. 11
0
  /**
   * Parse the repository.
   *
   * @param parser
   * @throws Exception
   */
  private void parseRepository(XmlPullParser parser) throws Exception {
    try {
      parser.require(XmlPullParser.START_DOCUMENT, null, null);
      parser.nextTag();
      if (parser.getName().equals("bundles")) parseOscar(parser);
      else {
        parser.require(XmlPullParser.START_TAG, null, "repository");
        date = parser.getAttributeValue(null, "lastmodified");
        name = parser.getAttributeValue(null, "name");
        if (name == null) name = "Untitled";

        while (parser.nextTag() == XmlPullParser.START_TAG) {
          if (parser.getName().equals("resource")) {
            ResourceImpl resource = new ResourceImpl(this, parser);
            resources.add(resource);
          } else if (parser.getName().equals("referral")) referral(parser);
          else
            throw new IllegalArgumentException(
                "Invalid tag in repository: " + url + " " + parser.getName());
        }
        parser.require(XmlPullParser.END_TAG, null, "repository");
      }
    } catch (XmlPullParserException e) {
      e.printStackTrace();
      throw new IllegalArgumentException(
          "XML unregognized around: " + e.getLineNumber() + " " + e.getMessage());
    }
  }
    @Override
    protected Object doInBackground(Object... params) {
      try {
        xp1 = new XmlParser();
        ht1 = xp1.process(geoCodingURL, 0);
        String cityname = ht1.get("cityname");

        countryCodeURL =
            "http://ws.geonames.org/countryCode?lat=6.858&lng=79.884&style=full&type=XML";
        ht3 = xp1.process(countryCodeURL, 2);
        String countryCode = ht3.get("countryCode");

        String otherLocationURL =
            "http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query="
                + cityname
                + ","
                + countryCode;
        System.out.println(otherLocationURL);
        ht2 = xp1.process(otherLocationURL, 1);

      } catch (IOException e) {
        showDialog(0);
      } catch (XmlPullParserException ex) {
        ex.printStackTrace();
      }

      Message message = callServiceHandler.obtainMessage();
      Bundle bundle = new Bundle();
      bundle.putSerializable("serviceResult", ht2);
      message.setData(bundle);
      callServiceHandler.sendMessage(message);

      return null;
    }
  public void testParse20100823_arrival() {
    TravelDelayParser parser = null;
    try {
      parser = getParser();
      parser.setEncoding("EUC-JP");
      parser.setAirline(true);
      parser.setArrival(true);
    } catch (XmlPullParserException e) {
      e.printStackTrace();
      fail(e.getMessage());
    }

    TravelDelayResult result = null;
    try {
      result =
          parser.parse(
              getClass().getResourceAsStream("/delay/travel_delay_result_detail_20100823.html"));
    } catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    }

    assertEquals(1, result.getCategories().size());

    Category c = result.getCategories().get(0);
    OperationCompany oc = c.getOperationCompanies().get(0);
    assertEquals(3, oc.getTravelDelays().size());
    TravelDelay td = oc.getTravelDelays().get(1);
    assertEquals("08/23 11:30", td.getDate());
    assertEquals("全日本空輸", td.getAirline());
    assertEquals("三宅島", td.getPlace());
    assertEquals("定刻13:40着 ANA1850便(三宅島→羽田) は欠航です。", td.getCondition());
  }
  public void testParse20100823_departure() {
    TravelDelayParser parser = null;
    try {
      parser = getParser();
      parser.setEncoding("EUC-JP");
      parser.setAirline(true);
      parser.setArrival(false);
    } catch (XmlPullParserException e) {
      e.printStackTrace();
      fail(e.getMessage());
    }

    TravelDelayResult result = null;
    try {
      result =
          parser.parse(
              getClass().getResourceAsStream("/delay/travel_delay_result_detail_20100823.html"));
    } catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    }

    assertEquals(1, result.getCategories().size());

    Category c = result.getCategories().get(0);
    OperationCompany oc = c.getOperationCompanies().get(0);
    assertEquals(4, oc.getTravelDelays().size());
    TravelDelay td = oc.getTravelDelays().get(3);
    assertEquals("08/23 08:30", td.getDate());
    assertEquals("日本航空", td.getAirline());
    assertEquals("旭川", td.getPlace());
    assertEquals("JAL1103便(羽田→旭川) は出発に遅れが出ています。07:25→08:29", td.getCondition());
  }
 /**
  * 获取远程WebService应用的数据列表
  *
  * @param SERVICE_NS 命名空间如:http://WebXml.com.cn/
  * @param SERVICE_URL WebService地址如:http://webservice.webxml.com.cn/WebServices/ WeatherWS.asmx
  * @param method WebService方法如:getRegionProvince
  * @return 数据列表
  */
 public static List<String> getServiceDataList(
     String SERVICE_NS, String SERVICE_URL, String method) {
   // 创建HttpTransportSE传输对象
   HttpTransportSE ht = new HttpTransportSE(SERVICE_URL);
   ht.debug = true;
   // 使用SOAP1.1协议创建Envelop对象
   SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
   // 实例化SoapObject对象
   SoapObject soapObject = new SoapObject(SERVICE_NS, method);
   envelope.bodyOut = soapObject;
   // 设置与.Net提供的Web Service保持较好的兼容性
   envelope.dotNet = true;
   try {
     // 调用Web Service
     ht.call(SERVICE_NS + method, envelope);
     if (envelope.getResponse() != null) {
       // 获取服务器响应返回的SOAP消息
       SoapObject result = (SoapObject) envelope.bodyIn;
       SoapObject detail = (SoapObject) result.getProperty(method + "Result");
       // 解析服务器响应的SOAP消息。
       return parseDataList(detail);
     }
   } catch (IOException e) {
     e.printStackTrace();
   } catch (XmlPullParserException e) {
     e.printStackTrace();
   }
   return null;
 }
Esempio n. 16
0
  public List<Bird> parseXML(Context context) {

    try {
      XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
      factory.setNamespaceAware(true);
      XmlPullParser xpp = factory.newPullParser();

      InputStream stream = context.getResources().openRawResource(com.example.birdnote.R.raw.birds);
      xpp.setInput(stream, null);

      int eventType = xpp.getEventType();
      while (eventType != XmlPullParser.END_DOCUMENT) {
        if (eventType == XmlPullParser.START_TAG) {
          handleStartTag(xpp.getName());
        } else if (eventType == XmlPullParser.END_TAG) {
          currentTag = null;
        } else if (eventType == XmlPullParser.TEXT) {
          handleText(xpp.getText());
        }
        eventType = xpp.next();
      }

    } catch (NotFoundException e) {
      Log.d(LOGTAG, e.getMessage());
    } catch (XmlPullParserException e) {
      Log.d(LOGTAG, e.getMessage());
    } catch (IOException e) {
      Log.d(LOGTAG, e.getMessage());
    }

    return birds;
  }
Esempio n. 17
0
 // 得到菜单的方法
 public Vector get_menu_ws(String resid) {
   String wsdlurl = "http://116.55.243.13:8080/school_res/services/restest";
   String webmethod_menu = "getMenu";
   String namespace = "http://res";
   String soapaction = namespace + webmethod_menu;
   SoapObject request = new SoapObject(namespace, webmethod_menu);
   request.addProperty("resid", resid);
   SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
   envelope.bodyOut = request;
   HttpTransportSE se = new HttpTransportSE(wsdlurl);
   Object ob = null;
   try {
     se.call(soapaction, envelope);
     if (envelope.getResponse() != null) {
       ob = envelope.getResponse();
     }
   } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (XmlPullParserException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   Vector ve = (Vector) ob;
   return ve;
 }
Esempio n. 18
0
    @Override
    protected Boolean doInBackground(Object... params) {
      boolean result = false;

      String pathToData = (String) params[0];
      table = (TableLayout) params[1];

      XmlPullParser data;
      try {
        Log.i("Comment", "Connecting to " + pathToData);

        URL xmlUrl = new URL(pathToData);
        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        data = factory.newPullParser();
        data.setInput(xmlUrl.openStream(), null);
      } catch (XmlPullParserException e) {
        data = null;
        e.printStackTrace();
      } catch (IOException e) {
        data = null;
        e.printStackTrace();
      }

      if (data != null) {
        try {
          Log.i("Note", "Processing XML");
          processHistory(data);
        } catch (XmlPullParserException e) {
          Log.e("My Debug Tag", "Pull Parser failure", e);
        } catch (IOException e) {
          Log.e("My Debug Tag", "IO Exception parsing XML", e);
        }
      }
      return result;
    }
Esempio n. 19
0
 // 得到公告名称
 public Vector get_title_ws() {
   Vector ve = null;
   String wsdlurl = "http://116.55.243.13:8080/ViewManage/services/ViewManage";
   String webmethod = "getTitle";
   String namespace = "http://ckpark.services.com";
   String soapaction = namespace + webmethod;
   SoapObject request = new SoapObject(namespace, webmethod);
   SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
   envelope.bodyOut = request;
   HttpTransportSE se = new HttpTransportSE(wsdlurl);
   Object result = null;
   try {
     se.call(soapaction, envelope);
     if (envelope.getResponse() != null) {
       result = envelope.getResponse();
     }
   } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (XmlPullParserException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   ve = (Vector) result;
   return ve;
 }
Esempio n. 20
0
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.activity_fragment_news, container, false);

    listView = (ListView) rootView.findViewById(R.id.newsListView);

    if (android.os.Build.VERSION.SDK_INT > 9) {
      StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
      StrictMode.setThreadPolicy(policy);
    }

    try {
      XMLPullParserHandler parser = new XMLPullParserHandler();
      items = parser.parse(XML_URL);
      NewsListAdapter adapter =
          new NewsListAdapter(this.getActivity(), R.layout.news_listrow_details, items);
      listView.setAdapter(adapter);
    } catch (IOException e) {
      e.printStackTrace();
    } catch (XmlPullParserException e) {
      e.printStackTrace();
    }

    listView.setOnItemClickListener(this);
    return rootView;
  }
Esempio n. 21
0
 private List<String> checkAssets(IProgress progress) {
   String fv = Version.getFullVersion(context);
   if (!fv.equalsIgnoreCase(context.getSettings().PREVIOUS_INSTALLED_VERSION.get())) {
     File applicationDataDir = context.getAppPath(null);
     applicationDataDir.mkdirs();
     if (applicationDataDir.canWrite()) {
       try {
         progress.startTask(context.getString(R.string.installing_new_resources), -1);
         AssetManager assetManager = context.getAssets();
         boolean isFirstInstall =
             context.getSettings().PREVIOUS_INSTALLED_VERSION.get().equals("");
         unpackBundledAssets(assetManager, applicationDataDir, progress, isFirstInstall);
         context.getSettings().PREVIOUS_INSTALLED_VERSION.set(fv);
         copyRegionsBoundaries();
         copyPoiTypes();
         for (String internalStyle :
             context.getRendererRegistry().getInternalRenderers().keySet()) {
           File fl = context.getRendererRegistry().getFileForInternalStyle(internalStyle);
           if (fl.exists()) {
             context.getRendererRegistry().copyFileForInternalStyle(internalStyle);
           }
         }
       } catch (SQLiteException e) {
         log.error(e.getMessage(), e);
       } catch (IOException e) {
         log.error(e.getMessage(), e);
       } catch (XmlPullParserException e) {
         log.error(e.getMessage(), e);
       }
     }
   }
   return Collections.emptyList();
 }
Esempio n. 22
0
  @SuppressWarnings("unchecked")
  private void xmlScan() {

    // the images can be scaled to 400px width by:
    // mkdir results
    // for f in *jpg; do echo "file $f"; convert "$f[400x>]" results/$f; done

    // parse the XML data for challenges
    // Get the Android-specific compiled XML parser.
    ArrayList<Challenge> challenges = null;
    int nOptions = 3;

    try {
      XmlResourceParser xrp = AbcSjovActivity.getAppContext().getResources().getXml(R.xml.q1);

      while (xrp.getEventType() != XmlResourceParser.END_DOCUMENT) {
        if (xrp.getEventType() == XmlResourceParser.START_TAG) {
          String s = xrp.getName();

          if (s.equals("level")) {
            challenges = new ArrayList<Challenge>();
            String optionStr = xrp.getAttributeValue(null, "options");
            nOptions = Integer.parseInt(optionStr);
          } else if (s.equals("question") && challenges != null) {

            Challenge ch = new Challenge();
            ch.resid = xrp.getAttributeResourceValue(null, "id", 0);
            ch.answer = xrp.getAttributeValue(null, "answer");
            ch.avoid = xrp.getAttributeValue(null, "avoid");
            ch.options = xrp.getAttributeValue(null, "options");
            ch.nOptions = nOptions;

            challenges.add(ch);
          }
        } else if (xrp.getEventType() == XmlResourceParser.END_TAG) {
          String s = xrp.getName();
          if (s.equals("level")) {
            challengeMap.add(challenges);
          }
        } else if (xrp.getEventType() == XmlResourceParser.TEXT) {
          // pass
        }
        xrp.next();
      }
      xrp.close();

      mLastChallengeSet = (ArrayList<Challenge>) challenges.clone();

    } catch (XmlPullParserException xppe) {
      Log.e(TAG, "Failure of .getEventType or .next, probably bad file format");
      xppe.toString();
    } catch (IOException ioe) {
      Log.e(TAG, "Unable to read resource file");
      ioe.printStackTrace();
    } catch (NullPointerException e) {
      Log.e(TAG, "NullPointerException in scanXml");
      e.printStackTrace();
    }
  }
  public List<Employee> parse(InputStream inputStream) {
    XmlPullParserFactory factory = null;
    XmlPullParser parser = null;

    try {
      factory = XmlPullParserFactory.newInstance();
      factory.setNamespaceAware(true);
      parser = factory.newPullParser();

      parser.setInput(inputStream, null);

      int eventType = parser.getEventType();

      while (eventType != XmlPullParser.END_DOCUMENT) {
        String tagname = parser.getName();

        switch (eventType) {
          case XmlPullParser.START_TAG:
            if (tagname.equalsIgnoreCase("employee")) {
              // create a new instance of employess
              employee = new Employee();
            }
            break;

          case XmlPullParser.TEXT:
            text = parser.getText();
            break;

          case XmlPullParser.END_TAG:
            if (tagname.equalsIgnoreCase("employee")) {
              // add employee object to list
              employees.add(employee);
            } else if (tagname.equalsIgnoreCase("name")) {
              employee.setName(text);
            } else if (tagname.equalsIgnoreCase("id")) {
              employee.setId(Integer.parseInt(text));
            } else if (tagname.equalsIgnoreCase("department")) {
              employee.setDepartment(text);
            } else if (tagname.equalsIgnoreCase("email")) {
              employee.setEmail(text);
            } else if (tagname.equalsIgnoreCase("type")) {
              employee.setType(text);
            }
            break;

          default:
            break;
        }

        eventType = parser.next();
      }
    } catch (XmlPullParserException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }

    return employees;
  }
Esempio n. 24
0
 protected synchronized void parse(XmlPullParser parser) throws XmlParseException, IOException {
   try {
     parser.nextTag();
     parseElement(parser);
   } catch (XmlPullParserException e) {
     throw new XmlParseException(parser, e.getMessage(), e);
   }
 }
Esempio n. 25
0
 public synchronized void parse(Reader reader) throws XmlParseException, IOException {
   try {
     XmlPullParser parser = createParser();
     parser.setInput(reader);
     parse(parser);
   } catch (XmlPullParserException e) {
     throw new XmlParseException(getParser(), e.getMessage(), e);
   }
 }
 static {
   try {
     PARSER_FACTORY = XmlPullParserFactory.newInstance();
     PARSER_FACTORY.setNamespaceAware(true);
     PARSER_FACTORY.setValidating(false);
   } catch (XmlPullParserException e) {
     log.severe(e.toString());
   }
 }
Esempio n. 27
0
 public Open311XmlParser() {
   parser = Xml.newPullParser();
   try {
     parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
   } catch (XmlPullParserException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
Esempio n. 28
0
  private void ReadXmlStreamed(InputStream readerStream) throws IOException, InvalidDBException {

    try {
      ReadDocumentStreamed(CreatePullParser(readerStream));
    } catch (XmlPullParserException e) {
      e.printStackTrace();
      throw new IOException(e.getLocalizedMessage());
    }
  }
  @Override
  public void onReceiveData(ApiType api, String json) {
    System.out.println("jsonAPiType=========================>" + json);

    if (json == null) {
      activityMes.showToast("数据获取失败");
      activityMes.disMissDialog();
      return;
    }
    if (api == ApiType.GET_SHOWDETAILSTWONEW) {

      if (json != null && !json.equals("")) {
        tInputStringStream = new ByteArrayInputStream(json.getBytes());
        XmlPullParser parser = Xml.newPullParser();
        try {
          parser.setInput(tInputStringStream, "UTF-8");
          int event = parser.getEventType();
          while (event != XmlPullParser.END_DOCUMENT) {
            Log.i("start_document", "start_document");
            switch (event) {
              case XmlPullParser.START_TAG:
                if ("return".equals(parser.getName())) {
                  try {
                    String xmlReturn = parser.nextText();
                    System.out.println("---------------------->" + xmlReturn);

                    results = JSON.parseArray(xmlReturn, ShowDetailsResult.class);

                    System.out.println("results========>" + results);
                    ShowDetailsAdapter adapter = new ShowDetailsAdapter(results);
                    System.out.println("adapter是否有数据==============>" + adapter);
                    list_Show_details.setAdapter(adapter);
                    adapter.notifyDataSetChanged();

                  } catch (IOException e) {
                    e.printStackTrace();
                  }
                }

                break;
            }
            try {
              event = parser.next();
            } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }
          }

        } catch (XmlPullParserException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
      activityMes.disMissDialog();
    }
  }
Esempio n. 30
0
 public boolean columnsDBParse(
     int
         idOfFile) // Функция, разбирающая xml файл с конфигами всех таблиц, сохраняющаяя названия
                   // таблиц, названия столбцов и типы столбцов
     {
   ArrayList<String[]> arrayList = new ArrayList<String[]>();
   ArrayList<String[]> typesArrayList = new ArrayList<String[]>();
   ArrayList<String> strings = new ArrayList<String>();
   ArrayList<String> typesStrings = new ArrayList<String>();
   ArrayList<String> list = new ArrayList<String>();
   try {
     XmlPullParser xpp = app.getResources().getXml(idOfFile);
     while (xpp.getEventType() != XmlPullParser.END_DOCUMENT) {
       switch (xpp.getEventType()) {
         case XmlPullParser.START_TAG:
           if (xpp.getDepth() == 2) {
             list.add(xpp.getAttributeValue(0));
           }
           if (xpp.getDepth() == 3) {
             strings.add(xpp.getAttributeValue(0));
             typesStrings.add(xpp.getAttributeValue(1));
           }
           break;
         case XmlPullParser.END_TAG:
           if (xpp.getDepth() == 2) {
             String[] helpArray = new String[strings.size()];
             helpArray = strings.toArray(helpArray);
             arrayList.add(helpArray);
             helpArray = new String[typesStrings.size()];
             helpArray = typesStrings.toArray(helpArray);
             typesArrayList.add(helpArray);
             typesStrings = new ArrayList<String>();
             strings = new ArrayList<String>();
           }
           break;
         default:
           break;
       }
       xpp.next();
     }
     this.DBcolumns = arrayList;
     this.DBtypes = typesArrayList;
     String[] arr = new String[list.size()];
     arr = list.toArray(arr);
     this.tables = arr;
   } catch (XmlPullParserException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
   if (this.DBcolumns == null || this.tables == null) {
     return false;
   } else {
     return true;
   }
 }