Results 1 to 3 of 3
  1. #1
    Eric is offline Senior Member
    Join Date
    Jun 2007
    Posts
    111
    Rep Power
    0

    Default Class to read and parse QIF

    I need a class to read and parse QIF (Quicken Interchange Format) files. If anyone knows of such a class I would appreciate a point in the right direction.

    Thanks,

    Eric

  2. #2
    Daniel is offline Member
    Join Date
    Jun 2007
    Posts
    91
    Rep Power
    0

    Default

    I think it would probably be better to use the OFX file format (newer).
    Same question apllies though.
    Greetings.
    Daniel:o

  3. #3
    Marcus is offline Member
    Join Date
    Jun 2007
    Posts
    92
    Rep Power
    0

    Default

    Hi, You posted the problem yourself, you googled .Luckily the end of this problem is near for developers.
    Krugle - Code Search for Developers
    I 'm not an expert on your question but I entered the search OFX file parse in krugle.

    The class name is ex. OFX1ToXML.java
    I hope to help you with this, if I did, please thank krugle..

    I copied the class below as a reference:

    Java Code:
    /******************************************************************************
      * The contents of this file are subject to the   Compiere License  Version 1.1
      * ("License"); You may not use this file except in compliance with the License
      * You may obtain a copy of the License at <a href="http://www.compiere.org/license.html" target="_blank" rel="nofollow">http://www.compiere.org/license.html</a>
      * Software distributed under the License is distributed on an  "AS IS"  basis,
      * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
      * the specific language governing rights and limitations under the License.
      * The Initial Developer is ActFact BV.
      * Copyright (C) 2003-2004 ActFact BV and Compiere Inc.;   All Rights Reserved.
      * Contributor(s): ______________________________________.
      *****************************************************************************/
     package org.compiere.impexp;
     
     import java.io.*;
     import java.util.logging.*;
     import org.compiere.util.*;
     
     /**
      *	Covert OFX 1XX (SQGML) into valid XML
      *
      *  SGML BASED OFX 1 compliant data is read from the BufferedReader
      *  passed to init. This class extends InputSream, allowing the
      *  XML compliant output data to be read from it.
      *
      *  @author Maarten Klinker
      * 	@version $Id: OFX1ToXML.java,v 1.4 2006/03/03 10:50:20 graemian Exp $
      */
     public final class OFX1ToXML extends InputStream implements Runnable
     {
      	/**	Reader object					*/
     	private PipedReader m_reader = new PipedReader();
     	/**	Writer object					*/
     	private BufferedWriter m_writer;
     	/**	Temp String					*/
     	private String m_ofx = "";
     
     	/**	Logger			*/
     	private CLogger	log = CLogger.getCLogger(getClass());
     	
     	/**
     	 * Constructor for OFX1ToXML
     	 * @param is InputStream
     	 * @throws IOException
     	 */
     	public OFX1ToXML(InputStream is) throws IOException
     	{
     		BufferedReader br = new BufferedReader(new InputStreamReader(is));
     		init(br);
     	}	//	OFX1ToXML
     	
     	/**
     	 * Constructor for OFX1ToXML
     	 * @param br BufferedReader
     	 * @throws IOException
     	 */
     	public OFX1ToXML(BufferedReader br) throws IOException
     	{
     		init(br);	
     	}	//	OFX1ToXML
     	
     	/**
     	 * Method init
     	 * @param br BufferedReader
     	 * @throws IOException
     	 */
     	public void init(BufferedReader br) throws IOException
     	{
     		m_writer = new BufferedWriter(new PipedWriter(m_reader));
     		String line = br.readLine();
     
     		write("<?xml version=\"1.0\"?>\n");
     		write("<?OFX ");
     		while(line.indexOf("<") != 0)
     		{
     			if (line.length() > 0) 
     			{
     				write(line.replaceAll(":", "=\"") + "\" ");
     			}
     			line = br.readLine();
     		}
     		write("?>\n");
     
     		while(line != null)
     		{
     			m_ofx += line + "\n";
     			line = br.readLine();
     		}
     		br.close();
     
     		new Thread(this).start();
     	}	//i	nit
     
     	/**
     	 * Method run
     	 * @see java.lang.Runnable#run()
     	 */
     	public void run()
     	{
     		boolean addCloseTag;
     		int tag2Start;
     		int tagStart;
     		int tagEnd;
     		String tag;
     		String line = "";
     
     		try
     		{
     			while(m_ofx != "")
     			{
     				addCloseTag = false;
     				tagStart = m_ofx.indexOf("<");
     				if (tagStart == -1) 
     				{
     					break;
     				}
     				tagEnd = m_ofx.indexOf(">");
     				if (tagEnd <= tagStart + 1) 
     				{
     					throw new IOException("PARSE ERROR: Invalid tag");
     				}
     				tag = m_ofx.substring(tagStart + 1, tagEnd);
     				if (tag.indexOf(" ") != -1) 
     				{
     					throw new IOException("PARSE ERROR: Invalid tag");
     				}
     				if (!tag.startsWith("/")) 
     				{
     					addCloseTag = (m_ofx.indexOf("</"+tag+">") == -1);
     				}
     				tag2Start = m_ofx.indexOf("<", tagEnd);
     				if (m_ofx.indexOf("\n", tagEnd) < tag2Start) 
     				{
     					tag2Start = m_ofx.indexOf("\n", tagEnd);
     				}
     				if (tag2Start == -1) 
     				{
     					tag2Start = m_ofx.length();
     				}
     				
     				String data=m_ofx.substring(tagEnd+1, tag2Start);
     				line = m_ofx.substring(0, tagEnd+1)+xmlEncodeTextAsPCDATA(data);
     				
     				m_ofx = m_ofx.substring(tag2Start);
     				if (addCloseTag) 
     				{
     					line += "</" + tag + ">";
     				}
     				write(line);
     			}
     			write(m_ofx);
     			m_writer.close();
     		}
     		catch (IOException e)
     		{
     			log.log(Level.SEVERE, "Ofx1To2Convertor: IO Exception", e);
     		}
     	}	//	run
     
     	/**
     	 * Method write
     	 * @param str String
     	 * @throws IOException
     	 */
     	private void write(String str) throws IOException
     	{
     		m_writer.write(str, 0, str.length());
     	}	//	write
     
     	/**
     	 * Method read
     	 * @return int
     	 * @throws IOException
     	 */
     	public int read() throws IOException
     	{
     		return m_reader.read();
     	}	//	read
     
     	/**
     	 * Method read
     	 * @param cbuf char[]
     	 * @param off int
     	 * @param len int
     	 * @return int
     	 * @throws IOException
     	 */
     	public int read(char[] cbuf, int off, int len) throws IOException
     	{
     		return m_reader.read(cbuf, off, len);
     	}	//	read
     	
     	
     	
     	
     	/**
     	 * Encodes strings for XML
     	 */
     	
     	 public final static String xmlEncodeTextAsPCDATA(String text) {
     		if (text == null)
     			return null;
     		char c;
     		StringBuffer n = new StringBuffer(text.length() * 2);
     		for (int i = 0; i < text.length(); i++) {
     			c = text.charAt(i);
     			switch (c) {
     			case '&':
     				n.append("&");
     				break;
     			case '<':
     				n.append("<");
     				break;
     			case '>':
     				n.append(">");
     				break;
     			case '"':
     				n.append(""");
     				break;
     			case '\'':
     				n.append("'");
     				break;
     			default: {
     				n.append(c);
     				break;
     			}
     			}
     		}
     
     		return n.toString();
     	}
     	 
     
     }	//Ofx1To2Convertor
    Greetings

    Marcus:cool:

Similar Threads

  1. Using Scanner class to read int value
    By Java Tip in forum Java Tip
    Replies: 1
    Last Post: 02-07-2009, 02:47 AM
  2. SAX Parse
    By bluefloyd8 in forum New To Java
    Replies: 1
    Last Post: 01-25-2008, 03:57 PM
  3. Using Scanner class to read int
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-18-2008, 11:50 AM
  4. Read from console (Scanner Class)
    By hey in forum New To Java
    Replies: 10
    Last Post: 12-11-2007, 10:11 PM
  5. how to parse an xml file
    By oregon in forum XML
    Replies: 3
    Last Post: 08-01-2007, 04:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •