Android Open Source - scanNedit X M L Parser






From Project

Back to project page scanNedit.

License

The source code is released under:

MIT License

If you think the Android project scanNedit listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.me.android.scanNedit;
/*from ww  w . j  a  va2 s  .  c  om*/
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import android.util.Log;

public class XMLParser {

  // constructor
  public XMLParser() {

  }

  /**
   * Getting XML from URL
   * @param url string
   * */
  public String getXmlFromUrl(String url) {
    String xml = "";
    String data = "";

      File myFile = new File(url);    
        if(myFile.exists()==true)
        {
                  
          try {
          //read xml to string  
            FileInputStream fIn = new FileInputStream(myFile);
              BufferedReader myReader = new BufferedReader(new InputStreamReader(fIn));
              while ((data = myReader.readLine()) != null) {
                    xml += data + "\n";
                }    
              myReader.close();      
          
          } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
                  
        }    
    // return XML
    return xml;
  }
  
  /**
   * Getting XML DOM element
   * @param XML string
   * */
  public Document getDomElement(String xml){
    Document doc = null;
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    try {

      DocumentBuilder db = dbf.newDocumentBuilder();

      InputSource is = new InputSource();
            is.setCharacterStream(new StringReader(xml));
            doc = db.parse(is); 

      } catch (ParserConfigurationException e) {
        Log.e("Error: ", e.getMessage());
        return null;
      } catch (SAXException e) {
        Log.e("Error: ", e.getMessage());
              return null;
      } catch (IOException e) {
        Log.e("Error: ", e.getMessage());
        return null;
      }

          return doc;
  }
  
  /** Getting node value
    * @param elem element
    */
   public final String getElementValue( Node elem ) {
       Node child;
       if( elem != null){
           if (elem.hasChildNodes()){
               for( child = elem.getFirstChild(); child != null; child = child.getNextSibling() ){
                   if( child.getNodeType() == Node.TEXT_NODE  ){
                       return child.getNodeValue();
                   }
               }
           }
       }
       return "";
   }
   
   /**
    * Getting node value
    * @param Element node
    * @param key string
    * */
   public String getValue(Element item, String str) {    
      NodeList n = item.getElementsByTagName(str);    
      return this.getElementValue(n.item(0));
    }
}




Java Source Code List

com.googlecode.leptonica.android.AdaptiveMap.java
com.googlecode.leptonica.android.Binarize.java
com.googlecode.leptonica.android.Box.java
com.googlecode.leptonica.android.Constants.java
com.googlecode.leptonica.android.Convert.java
com.googlecode.leptonica.android.Enhance.java
com.googlecode.leptonica.android.JpegIO.java
com.googlecode.leptonica.android.Pix.java
com.googlecode.leptonica.android.Pixa.java
com.googlecode.leptonica.android.ReadFile.java
com.googlecode.leptonica.android.Rotate.java
com.googlecode.leptonica.android.Scale.java
com.googlecode.leptonica.android.Skew.java
com.googlecode.leptonica.android.WriteFile.java
com.googlecode.tesseract.android.TessBaseAPI.java
com.markupartist.android.widget.ActionBar.java
com.markupartist.android.widget.ActionBar_three.java
com.markupartist.android.widget.ActionBar_two.java
com.markupartist.android.widget.ScrollingTextView.java
com.me.android.scanNedit.CameraActivity.java
com.me.android.scanNedit.CropOptionAdapter.java
com.me.android.scanNedit.CropOption.java
com.me.android.scanNedit.FileCache.java
com.me.android.scanNedit.GalleryActivity.java
com.me.android.scanNedit.HelpActivity.java
com.me.android.scanNedit.ImageLoader.java
com.me.android.scanNedit.LazyAdapter.java
com.me.android.scanNedit.MemoryCache.java
com.me.android.scanNedit.Picture.java
com.me.android.scanNedit.SampleActivity.java
com.me.android.scanNedit.StartActivity.java
com.me.android.scanNedit.TessBaseAPITest.java
com.me.android.scanNedit.Utils.java
com.me.android.scanNedit.XMLParser.java