private void readXML() throws XmlPullParserException, IOException {
   String tagName = "";
   XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
   factory.setNamespaceAware(true);
   XmlPullParser xpp = factory.newPullParser();
   try {
     InputStream in = openFileInput("settings.xml");
     InputStreamReader isr = new InputStreamReader(in);
     BufferedReader reader = new BufferedReader(isr);
     String str;
     StringBuffer buf = new StringBuffer();
     while ((str = reader.readLine()) != null) {
       buf.append(str);
     }
     in.close();
     xpp.setInput(new StringReader(buf.toString()));
     int eventType = xpp.getEventType();
     while (eventType != XmlPullParser.END_DOCUMENT) {
       if (eventType == XmlPullParser.START_DOCUMENT) {
       } else if (eventType == XmlPullParser.END_DOCUMENT) {
       } else if (eventType == XmlPullParser.START_TAG) {
         tagName = xpp.getName();
       } else if (eventType == XmlPullParser.END_TAG) {
       } else if (eventType == XmlPullParser.TEXT) {
         if (tagName.contains("sound_setting")) {
           soundEnabled = Boolean.parseBoolean(xpp.getText().toString());
         }
       }
       eventType = xpp.next();
     }
   } catch (Exception FileNotFoundException) {
     System.out.println("File Not Found");
   }
 }
Example #2
0
  public static String getMediaUrl(String response) throws XmlPullParserException, IOException {

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

    String result = null;

    parser.setInput(new StringReader(response));
    int eventType = parser.getEventType();
    while (eventType != XmlPullParser.END_DOCUMENT) {
      String name = null;
      switch (eventType) {
        case XmlPullParser.START_DOCUMENT:
          break;
        case XmlPullParser.START_TAG:
          name = parser.getName();
          if (name.equalsIgnoreCase("mediaurl")) {
            result = parser.nextText();
          }
          break;
        case XmlPullParser.END_TAG:
          break;
      }
      eventType = parser.next();
    }

    return result;
  }
Example #3
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;
  }
 private static XmlPullParser buildParser(CharSequence contents) throws XmlPullParserException {
   XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
   factory.setNamespaceAware(true);
   XmlPullParser xpp = factory.newPullParser();
   xpp.setInput(new StringReader(contents.toString()));
   return xpp;
 }
Example #5
0
  public static void main(String args[]) throws XmlPullParserException, IOException {

    XmlPullParserFactory factory =
        XmlPullParserFactory.newInstance(
            System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
    factory.setNamespaceAware(false);
    System.err.println("using factory " + factory.getClass());

    XmlPullParser xpp = factory.newPullParser();
    System.err.println("using parser " + xpp.getClass());

    XmlPullCount app = new XmlPullCount();

    app.verbose = true;
    for (int c = 0; c < 2; ++c) {
      System.err.println("run#" + c);
      app.resetCounters();
      if (args.length == 0) {
        System.err.println("Parsing simple sample XML length=" + SAMPLE_XML.length());
        xpp.setInput(new StringReader(SAMPLE_XML));
        app.countXml(xpp);
      } else {
        // r (int i = 0; i < args.length; i++) {

        File f = new File(args[0]);
        System.err.println("Parsing file: " + args[0] + " length=" + f.length());
        // xpp.setInput ( new FileReader ( args [0] ) );
        xpp.setInput(new FileInputStream(args[0]), "UTF8");
        app.countXml(xpp);
        //
      }
      app.printReport();
    }
    System.err.println("finished");
  }
 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;
 }
  public static Map<String, String> fetchValuesFromReponse(String response) {
    Map<String, String> responseValues = new HashMap<String, String>();
    try {

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

      xpp.setInput(new StringReader(response));
      int eventType = xpp.getEventType();
      String tag = null;
      String value = null;
      while (eventType != XmlPullParser.END_DOCUMENT) {
        if (eventType == XmlPullParser.START_TAG && xpp.getName() != null) {
          tag = xpp.getName();
          eventType = xpp.next();
          value = xpp.getText();
          if (responseValues.keySet().contains(tag)) {
            value = responseValues.get(tag) + "##" + value;
          }
          responseValues.put(tag, value);
        } else {
          eventType = xpp.next();
        }
      }
    } catch (Exception anExcep) {
      anExcep.printStackTrace();
    }
    return responseValues;
  }
Example #8
0
  /*
   * Parse 'content'
   *
   * Logs used to debug
   */
  public String parseThumbLink(String str) throws XmlPullParserException, IOException {
    String src = null;

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

    xpp.setInput(new StringReader(str));
    int eventType = xpp.getEventType();
    while (eventType != XmlPullParser.END_DOCUMENT) {
      if (eventType == XmlPullParser.START_DOCUMENT) {
        // Log.d(logtag, "Start document");
      } else if (eventType == XmlPullParser.START_TAG) {
        // Log.d(logtag, "Start tag " + xpp.getName());
        if (xpp.getName().equals("img")) {
          src = xpp.getAttributeValue(null, "src");
          Log.d(logtag, "src: " + xpp.getAttributeValue(null, "src"));
        }
      } else if (eventType == XmlPullParser.END_TAG) {
        // Log.d(logtag, "End tag " + xpp.getName());
      } else if (eventType == XmlPullParser.TEXT) {
        // Log.d(logtag, "Text " + xpp.getText());
      }
      eventType = xpp.next();
    }

    return src;
  }
  // -----------------------------------------------------------------------------------
  private static String getXMLMessage(String msg)
      throws JSONException, XmlPullParserException, IOException {

    String xmlMessage = null;
    InputStream is = new ByteArrayInputStream(msg.getBytes());
    // Using Pull Parser
    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
    factory.setNamespaceAware(true);
    XmlPullParser xmlPullParser = factory.newPullParser();
    xmlPullParser.setInput(is, "UTF-8");

    // --------------------------------------------------------
    // Start Parsing XML Data
    // --------------------------------------------------------
    while (xmlPullParser.next() != XmlPullParser.END_DOCUMENT) {

      if (xmlPullParser.getEventType() == XmlPullParser.START_TAG) {
        if (xmlPullParser.getName().equals("string")) {
          xmlPullParser.next();
          xmlMessage = xmlPullParser.getText();
          break;
        }
      }
    }

    return xmlMessage;
  }
Example #10
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();
      }
    }
  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;
  }
 static {
   try {
     sXmlPullParserFactory = XmlPullParserFactory.newInstance();
     sXmlPullParserFactory.setNamespaceAware(true);
   } catch (XmlPullParserException e) {
     LOGE(YahooPlacesAPIClient.TAG, "Could not instantiate XmlPullParserFactory", e);
   }
 }
 static {
   try {
     factory = XmlPullParserFactory.newInstance(MXParser.class.getName(), null);
     factory.setNamespaceAware(true);
   } catch (XmlPullParserException e) {
     log.error("Error creating a parser factory", e);
   }
 }
 /**
  * Allocate and initial an XmlPullParser
  *
  * <p>At the time this code was written the XmlPullParser did not support validation, so the call
  * to setValidating() is passed "false".
  */
 private XmlPullParser getParser() throws XmlPullParserException {
   XmlPullParserFactory factory;
   factory = XmlPullParserFactory.newInstance();
   factory.setNamespaceAware(true);
   factory.setValidating(false);
   XmlPullParser parser = factory.newPullParser();
   return parser;
 } // getParser
  public XmlPullParserFactory getXPPFactory() throws XmlPullParserException {
    if (xppFactory == null) {
      xppFactory = XmlPullParserFactory.newInstance();
    }

    xppFactory.setNamespaceAware(true);

    return xppFactory;
  }
 static {
   try {
     PARSER_FACTORY = XmlPullParserFactory.newInstance();
     PARSER_FACTORY.setNamespaceAware(true);
     PARSER_FACTORY.setValidating(false);
   } catch (XmlPullParserException e) {
     log.severe(e.toString());
   }
 }
  public boolean process() {
    boolean status = true;
    Application currentRecord = null;
    boolean inEntry = false;
    String textValue = "";

    try {
      XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
      factory.setNamespaceAware(true);
      XmlPullParser xpp = factory.newPullParser();
      xpp.setInput(new StringReader(this.xmlData));
      int eventType = xpp.getEventType();

      while (eventType != XmlPullParser.END_DOCUMENT) {
        String tagName = xpp.getName();
        switch (eventType) {
          case XmlPullParser.START_TAG:
            // Log.d("ParseApplications", "Starting tag for " + tagName);
            if (tagName.equalsIgnoreCase("entry")) {
              inEntry = true;
              currentRecord = new Application();
            }
            break;

          case XmlPullParser.TEXT:
            textValue = xpp.getText();
            break;

          case XmlPullParser.END_TAG:
            // Log.d("ParseApplications", "Ending tag for " + tagName);
            if (inEntry) {
              if (tagName.equalsIgnoreCase("entry")) {
                applications.add(currentRecord);
                inEntry = false;
              } else if (tagName.equalsIgnoreCase("name")) {
                currentRecord.setName(textValue);
              } else if (tagName.equalsIgnoreCase("artist")) {
                currentRecord.setArtist(textValue);
              } else if (tagName.equalsIgnoreCase("releaseDate")) {
                currentRecord.setReleaseDate(textValue);
              }
            }
            break;

          default:
            // nothing else to do
        }
        eventType = xpp.next();
      }

    } catch (Exception e) {
      status = false;
      e.printStackTrace();
    }
    return true;
  }
Example #18
0
  private static XmlPullParser CreatePullParser(InputStream readerStream)
      throws XmlPullParserException {
    XmlPullParserFactory xppf = XmlPullParserFactory.newInstance();
    xppf.setNamespaceAware(false);

    XmlPullParser xpp = xppf.newPullParser();
    xpp.setInput(readerStream, null);

    return xpp;
  }
Example #19
0
 private static synchronized XmlPullParserFactory getParserFactory()
     throws XmlPullParserException {
   if (factory == null) {
     factory =
         XmlPullParserFactory.newInstance(
             System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
     factory.setNamespaceAware(true);
   }
   return factory;
 }
Example #20
0
  // ----------------------------------------------------------------------------
  private ArrayList<TranslationData> parseTranslation(InputStream is)
      throws XmlPullParserException, IOException {

    ArrayList<TranslationData> translationList = new ArrayList<TranslationData>();

    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
    factory.setNamespaceAware(true);
    XmlPullParser xmlPullParser = factory.newPullParser();
    xmlPullParser.setInput(is, "UTF-8");

    while (xmlPullParser.next() != XmlPullParser.END_DOCUMENT) {
      if (xmlPullParser.getEventType() == XmlPullParser.START_TAG) {
        if (xmlPullParser.getName().equals("translation")) {
          TranslationData info = new TranslationData();

          while (xmlPullParser.next() != XmlPullParser.END_DOCUMENT) {
            if (xmlPullParser.getEventType() == XmlPullParser.START_TAG) {
              if (xmlPullParser.getName().equals("user_name")) {
                String userName = xmlPullParser.nextText();
                info.setUserName(userName);
                continue;
              }
              if (xmlPullParser.getName().equals("service")) {
                String service = xmlPullParser.nextText();
                info.setService(service);
                continue;
              }
              if (xmlPullParser.getName().equals("from")) {
                String from = xmlPullParser.nextText();
                info.setFrom(from);
                continue;
              }
              if (xmlPullParser.getName().equals("to")) {
                String to = xmlPullParser.nextText();
                info.setTo(to);
                continue;
              }
              if (xmlPullParser.getName().equals("engine")) {
                String engine = xmlPullParser.nextText();
                info.setEngine(engine);
                continue;
              }
            }
            if (xmlPullParser.getEventType() == XmlPullParser.END_TAG) {
              if (xmlPullParser.getName().equals("translation")) {
                translationList.add(info);
                break;
              }
            }
          }
        }
      }
    }
    return translationList;
  }
Example #21
0
  public static ArrayList<HashMap<String, String>> getAttendaceList(String response)
      throws XmlPullParserException, IOException {

    item = null;
    itemList = null;

    double count = 0.0;
    DecimalFormat df = new DecimalFormat("#.##");

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

    parser.setInput(new StringReader(response));
    int eventType = parser.getEventType();
    while (eventType != XmlPullParser.END_DOCUMENT) {
      String name = null;
      switch (eventType) {
        case XmlPullParser.START_DOCUMENT:
          itemList = new ArrayList<HashMap<String, String>>();
          break;
        case XmlPullParser.START_TAG:
          name = parser.getName();
          if (name.equalsIgnoreCase("AttendaceStatistics")) {
            item = new HashMap<String, String>();
          } else if (item != null) {
            if (name.equalsIgnoreCase("Image")) {
              item.put("image", parser.nextText());
            } else if (name.equalsIgnoreCase("Name")) {
              item.put("name", parser.nextText());
            } else if (name.equalsIgnoreCase("NickName")) {
              item.put("nickName", parser.nextText());
            } else if (name.equalsIgnoreCase("Trophy")) {
              item.put("trophy", parser.nextText());
            } else if (name.equalsIgnoreCase("UserId")) {
              item.put("id", parser.nextText());
            } else if (name.equalsIgnoreCase("PercentageAttendance")) {
              count = Double.parseDouble(parser.nextText());
              item.put("count", df.format(count));
            }
          }
          break;
        case XmlPullParser.END_TAG:
          name = parser.getName();
          if (name.equalsIgnoreCase("AttendaceStatistics") && item != null) {
            itemList.add(item);
          }
          break;
      }
      eventType = parser.next();
    }

    return itemList;
  }
  public List<Card> parse(InputStream is) {

    XmlPullParserFactory factory = null;
    XmlPullParser parser = null;

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

      parser = factory.newPullParser();
      parser.setInput(is, null);

      int eventType = parser.getEventType();
      while (eventType != XmlPullParser.END_DOCUMENT) {
        String tagname = parser.getName();
        switch (eventType) {
          case XmlPullParser.START_TAG:
            if (tagname.equalsIgnoreCase("card")) {
              card = new Card();
            }
            break;
          case XmlPullParser.TEXT:
            text = parser.getText();
            break;

          case XmlPullParser.END_TAG:
            if (tagname.equalsIgnoreCase("card")) {
              cards.add(card);
            } else if (tagname.equalsIgnoreCase("name")) {
              card.setName(text);
            } else if (tagname.equalsIgnoreCase("id")) {
              card.setId(Integer.parseInt(text));
            } else if (tagname.equalsIgnoreCase("month")) {
              card.setMonth(text);
            } else if (tagname.equalsIgnoreCase("description")) {
              card.setDescription(text);
            } else if (tagname.equalsIgnoreCase("step")) {
              card.addDirection(text);
            } else if (tagname.equalsIgnoreCase("item")) {
              card.addMaterial(text);
            }
            break;

          default:
            break;
        }
        eventType = parser.next();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    return cards;
  }
Example #23
0
  /**
   * Reads an Opml document and returns a list of all OPML elements it can find
   *
   * @throws IOException
   * @throws XmlPullParserException
   */
  public ArrayList<OpmlElement> readDocument(Reader reader)
      throws XmlPullParserException, IOException {
    elementList = new ArrayList<OpmlElement>();
    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
    factory.setNamespaceAware(true);
    XmlPullParser xpp = factory.newPullParser();
    xpp.setInput(reader);
    int eventType = xpp.getEventType();

    while (eventType != XmlPullParser.END_DOCUMENT) {
      switch (eventType) {
        case XmlPullParser.START_DOCUMENT:
          if (BuildConfig.DEBUG) Log.d(TAG, "Reached beginning of document");
          break;
        case XmlPullParser.START_TAG:
          if (xpp.getName().equals(OpmlSymbols.OPML)) {
            isInOpml = true;
            if (BuildConfig.DEBUG) Log.d(TAG, "Reached beginning of OPML tree.");
          } else if (isInOpml && xpp.getName().equals(OpmlSymbols.OUTLINE)) {
            if (BuildConfig.DEBUG) Log.d(TAG, "Found new Opml element");
            OpmlElement element = new OpmlElement();

            final String title = xpp.getAttributeValue(null, OpmlSymbols.TITLE);
            if (title != null) {
              Log.i(TAG, "Using title: " + title);
              element.setText(title);
            } else {
              Log.i(TAG, "Title not found, using text");
              element.setText(xpp.getAttributeValue(null, OpmlSymbols.TEXT));
            }
            element.setXmlUrl(xpp.getAttributeValue(null, OpmlSymbols.XMLURL));
            element.setHtmlUrl(xpp.getAttributeValue(null, OpmlSymbols.HTMLURL));
            element.setType(xpp.getAttributeValue(null, OpmlSymbols.TYPE));
            if (element.getXmlUrl() != null) {
              if (element.getText() == null) {
                Log.i(TAG, "Opml element has no text attribute.");
                element.setText(element.getXmlUrl());
              }
              elementList.add(element);
            } else {
              if (BuildConfig.DEBUG) Log.d(TAG, "Skipping element because of missing xml url");
            }
          }
          break;
      }
      eventType = xpp.next();
    }

    if (BuildConfig.DEBUG) Log.d(TAG, "Parsing finished.");

    return elementList;
  }
Example #24
0
  public boolean process() {
    boolean operationStatus = true;
    Application currentRecord = null;
    boolean inEntry = false;
    String textValue = "";

    try {
      XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
      factory.setNamespaceAware(true);
      XmlPullParser xpp = factory.newPullParser();
      xpp.setInput(new StringReader(this.data));
      int eventType = xpp.getEventType();

      while (eventType != XmlPullParser.END_DOCUMENT) {
        String tagName = xpp.getName();

        if (eventType == XmlPullParser.START_TAG) {
          if (tagName.equalsIgnoreCase("entry")) {
            inEntry = true;
            currentRecord = new Application();
          }
        } else if (eventType == XmlPullParser.TEXT) {
          textValue = xpp.getText();
        } else if (eventType == XmlPullParser.END_TAG) {
          if (inEntry) {
            if (tagName.equalsIgnoreCase("entry")) {
              apps.add(currentRecord);
              inEntry = false;
            }
            if (tagName.equalsIgnoreCase("name")) {
              currentRecord.setName(textValue);
            } else if (tagName.equalsIgnoreCase("artist")) {
              currentRecord.setArtist(textValue);
            } else if (tagName.equalsIgnoreCase("releaseDate")) {
              currentRecord.setReleaseDate(textValue);
            }
          }
        }
        eventType = xpp.next();
      }
    } catch (Exception e) {
      e.printStackTrace();
      operationStatus = false;
    }
    for (Application app : apps) {
      Log.d("LOG", "***********************");
      Log.d("LOG", app.getName());
      Log.d("LOG", app.getArtist());
      Log.d("LOG", app.getReleaseDate());
    }
    return operationStatus;
  }
Example #25
0
  public static ArrayList<HashMap<String, String>> getCommentsList(String response)
      throws XmlPullParserException, IOException {

    item = null;
    itemList = null;

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

    parser.setInput(new StringReader(response));
    int eventType = parser.getEventType();
    while (eventType != XmlPullParser.END_DOCUMENT) {
      String name = null;
      switch (eventType) {
        case XmlPullParser.START_DOCUMENT:
          itemList = new ArrayList<HashMap<String, String>>();
          break;
        case XmlPullParser.START_TAG:
          name = parser.getName();
          if (name.equalsIgnoreCase("Comments")) {
            item = new HashMap<String, String>();
          } else if (item != null) {
            if (name.equalsIgnoreCase("Image")) {
              item.put("image", parser.nextText());
            } else if (name.equalsIgnoreCase("Name")) {
              item.put("name", parser.nextText());
            } else if (name.equalsIgnoreCase("UserId")) {
              item.put("userId", parser.nextText());
            } else if (name.equalsIgnoreCase("Comment")) {
              item.put("comment", parser.nextText());
            } else if (name.equalsIgnoreCase("CommentId")) {
              item.put("commentId", parser.nextText());
            } else if (name.equalsIgnoreCase("CommentTypeId")) {
              item.put("commentTypeId", parser.nextText());
            } else if (name.equalsIgnoreCase("Type")) {
              item.put("type", parser.nextText());
            }
          }
          break;
        case XmlPullParser.END_TAG:
          name = parser.getName();
          if (name.equalsIgnoreCase("Comments") && item != null) {
            itemList.add(item);
          }
          break;
      }
      eventType = parser.next();
    }

    return itemList;
  }
Example #26
0
    public void Parsing() {
      String link = "http://52.68.141.174/xml/file.xml";

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

        URL Server = new URL(link);
        InputStream is = Server.openStream();
        xpp.setInput(is, "UTF-8");
        String tag;
        // String temp;
        int tagId = 0;

        int eventType = xpp.getEventType();

        while (eventType != XmlPullParser.END_DOCUMENT) {
          switch (eventType) {
            case XmlPullParser.START_DOCUMENT:
              break;
            case XmlPullParser.END_DOCUMENT:
              break;
            case XmlPullParser.START_TAG:
              tag = xpp.getName();

              if (tag.equals("path")) tagId = 1;
              else if (tag.equals("time")) tagId = 2;
              else if (tag.equals("filecode")) tagId = 3;
              break;
            case XmlPullParser.END_TAG:
              break;
            case XmlPullParser.TEXT:
              if (tagId == 1) {
                arrayList_path.add(xpp.getText());
              } else if (tagId == 2) {
                arrayList_time.add(xpp.getText());
              } else if (tagId == 3) {
                arrayList_filecode.add(xpp.getText());
              }
              tagId = 0;
              break;
          }
          eventType = xpp.next();
        }

      } catch (XmlPullParserException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  public ArrayList<HashMap<String, String>> dataadapter(Context context) {

    try {
      InputStream istr = context.getAssets().open(assetName);
      XmlPullParserFactory factory = XmlPullParserFactory.newInstance();

      factory.setNamespaceAware(true);
      XmlPullParser xrp = factory.newPullParser();
      xrp.setInput(istr, "UTF-8");
      xrp.next();
      int eventType = xrp.getEventType();

      String code = "";
      String displayName = "";

      while (eventType != XmlPullParser.END_DOCUMENT) {
        if (eventType == XmlPullParser.START_TAG) {

          String tagName = xrp.getName().toString();

          if (tagName.equals("concept")) {
            code = xrp.getAttributeValue(null, "code");
          }

          if (tagName.equals("displayName")) {
            displayName = xrp.nextText();

            HashMap<String, String> map = new HashMap<String, String>();
            map.put("NAME", displayName);
            map.put("CODE", code);
            dataItems.add(map);

            // Log.i("dn", code + " -- " + displayName);
          }

          if (tagName.equals("vocabulary")) {
            name = xrp.getAttributeValue(null, "name");
            version = xrp.getAttributeValue(null, "version");
            status = xrp.getAttributeValue(null, "status");
            id = xrp.getAttributeValue(null, "id");
            // Log.i("debug", name + ":" + version + ":" + status 	+ ":" + id);
          }
        }

        eventType = xrp.next();
      }
    } catch (Exception e) {
      Log.e("Error: ", name);
    }
    return dataItems;
  }
  public List<Employee> parse(String fileData) {
    InputStream is = new ByteArrayInputStream(fileData.getBytes(StandardCharsets.UTF_8));
    try {
      XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
      factory.setNamespaceAware(true);
      XmlPullParser parser = factory.newPullParser();

      parser.setInput(is, 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 employee
              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("id")) {
              employee.setId(Integer.parseInt(text));
            } else if (tagname.equalsIgnoreCase("name")) {
              employee.setName(text);
            } else if (tagname.equalsIgnoreCase("salary")) {
              employee.setSalary(Float.parseFloat(text));
            }
            break;

          default:
            break;
        }
        eventType = parser.next();
      }

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

    return employees;
  }
 public List parse(InputStream in) throws XmlPullParserException, IOException {
   try {
     XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
     factory.setNamespaceAware(true);
     XmlPullParser parser = factory.newPullParser();
     // XmlPullParser parser = Xml.newPullParser();
     parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
     parser.setInput(in, null);
     parser.nextTag();
     return readFeed(parser);
   } finally {
     in.close();
   }
 }
Example #30
0
  private void findIdea(String xmlString) {

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

      xpp.setInput(new StringReader(xmlString));

      int eventType = xpp.getEventType();

      while (eventType != XmlPullParser.END_DOCUMENT) {

        if (eventType == XmlPullParser.START_DOCUMENT) {

          Log.i("Start document", "start document");

        } else if (eventType == XmlPullParser.START_TAG) {

          Log.i("Start tag", "" + xpp.getName());

          if (xpp.getName().equals("content")) {

            xpp.next();

            String result = xpp.getText();
            Message msg = Message.obtain();
            msg.obj = result;

            handler.sendMessage(msg);
          }
        } else if (eventType == XmlPullParser.END_TAG) {

          Log.i("End tag", "" + xpp.getName());

        } else if (eventType == XmlPullParser.TEXT) {

          Log.i("TEXT", "" + xpp.getText());
        }

        eventType = xpp.next();
      }

    } catch (Exception e) {

      Log.e("error", "" + e.getMessage());
    }

    Log.e("end program", "The End!!");
  }