Android Open Source - ePUB-Converter X M L Parser






From Project

Back to project page ePUB-Converter.

License

The source code is released under:

GNU General Public License

If you think the Android project ePUB-Converter 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

/*
Copyright (C)2011 Ezio Querini/*from w  w  w.j  ava2s .co m*/

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.srsahu.epubconverter;

import java.io.IOException;
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.xml.sax.InputSource;
import org.xml.sax.SAXException;

public class XMLParser {
  // Get DOM element
  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) {
      System.err.println("Error: " + e.getMessage());
      return null;
    } catch (SAXException e) {
      System.err.println("Error: " + e.getMessage());
      return null;
    } catch (IOException e) {
      System.err.println("Error: " + e.getMessage());
      return null;
    }

    return doc;
  }

  // Get attribute value
  public String getValue(Element item, String str) {
    return item.getAttribute(str);
  }

  // Get element value
  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 "";
  }  
}




Java Source Code List

com.srsahu.epubconverter.Convert.java
com.srsahu.epubconverter.FileChooser.java
com.srsahu.epubconverter.Info.java
com.srsahu.epubconverter.License.java
com.srsahu.epubconverter.Prefs.java
com.srsahu.epubconverter.Preview.java
com.srsahu.epubconverter.ReadPdf.java
com.srsahu.epubconverter.WriteZip.java
com.srsahu.epubconverter.XMLParser.java
com.srsahu.epubconverter.epubconverter.java