java tecrübem yoktur. ama elements[7].length() gibi bir çağrıda bulunmak için elements[7] in var olması gereklidir büyük olasılıkla. text2.txt dosyanın formatının sıkıntısız olduğuna eminmisniz?
2009/3/27 Ayris Uygur <[email protected]> > > > yanıtın için teşekkür ederim, fakat o kadar amatör bir hata olduğunu > sanmıyorum, çünkü array size'ını 20 değil 1000 yaptığımda da aynı > exception'ı alıyorum, size'ı artırarak sadece boş yere memory'de yer açmış > oldum.. :) > > > --- On Thu, 3/26/09, ANIL KARADAĞ <[email protected]> wrote: > > > From: ANIL KARADAĞ <[email protected]> > > Subject: [Linux-programlama] Re: text dosyasını xml'e çevirmek.. > > To: "Özgür yazılımlarla çeşitli dillerde yazılım geliştirme" < > [email protected]> > > Date: Thursday, March 26, 2009, 5:26 PM > > String [] elements=new String > > [20]; > > > > Bir string dizisinde her bir elemanın max 20 karakterli > > olmasını ifade ediyorsun ancak owner ı işlerken split > > ile boldugun bolum 20 karakterden fazla ise sen bu hatayı > > alırsın. Sana söyledigi sey su en fazla 20 elemanlı bir > > diziye 20 den fazla eleman atamaya calisiyorsun. > > > > > > > > > > 26 Mart 2009 Perşembe 11:43 > > tarihinde Ayris Uygur <[email protected]> > > yazdı: > > > > > > > > > > > > slm ark.lar..ben bir text dosyasındaki bilgileri okutup, > > xml dosyasına yazmak istiyorum..fakat program sadece > > dosyamdaki ilk 2 property'i ("domain_name" ve > > "address") alarak xml'e > > yazıyor.."server"dan sonrasını > > ("owner", "owner e-mail" vs.) almaya > > çalıştığımda aşağıdaki exception'ı > > alıyorum... > > > > > > > > > > java.lang.ArrayIndexOutOfBoundsException: 2 > > > > at ToXML.process(ToXML.java:92) > > > > at ToXML.doit(ToXML.java:32) > > > > at ToXML.main(ToXML.java:22) > > > > > > > > aldığım satırlar array size'ını nasıl geçiyor > > olabilir, array'im 20'lik sonuçta..bir fikriniz var > > mı, şimdiden teşekkür ediyorum.. :) > > > > > > > > > > > > > > > > input dosyam aşağıdaki şekilde : > > > > > > > > text2.txt > > > > ----------------------- > > > > Name: Inverse IPv4 Domain > > > > Address: 4676 Admiralty Way > > > > Server: ns1.blabla.com > > > > Server2: ns2.blabla.com > > > > Owner: Internet Assigned Numbers Authority (IANA) > > > > Owner email: [email protected] > > > > Registration date: 13-October-2001 > > > > Expiration Date: 20-October-2001 > > > > > > > > > > > > > > > > source code: > > > > ------------------------- > > > > import java.io.*; > > > > import java.util.Scanner; > > > > > > > > // SAX classes. > > > > import org.xml.sax.*; > > > > import org.xml.sax.helpers..*; > > > > > > > > import javax.xml.parsers.*; > > > > import javax.xml.transform.*; > > > > import javax.xml.transform.stream.*; > > > > import javax.xml.transform.sax.*; > > > > > > > > public class ToXML { > > > > > > > > BufferedReader in; > > > > StreamResult out; > > > > > > > > TransformerHandler th; > > > > AttributesImpl atts; > > > > > > > > public static void main (String args[]) { > > > > new ToXML().doit(); > > > > } > > > > > > > > public void doit () { > > > > try{ > > > > in = new BufferedReader(new > > FileReader("/home/ayris/Masaüstü/test2.txt")); > > > > out = new > > StreamResult("/home/ayris/Masaüstü/test2.xml"); > > > > initXML(); > > > > String str; > > > > while ((str = in.readLine()) != null) { > > > > process(str); > > > > } > > > > in.close(); > > > > closeXML(); > > > > } > > > > catch (Exception e) { e.printStackTrace(); } > > > > } > > > > > > > > public void initXML() throws > > ParserConfigurationException, > > > > TransformerConfigurationException, SAXException { > > > > // JAXP + SAX > > > > SAXTransformerFactory tf = > > > > (SAXTransformerFactory) > > SAXTransformerFactory.newInstance(); > > > > > > > > th = tf.newTransformerHandler(); > > > > Transformer serializer = th.getTransformer(); > > > > > > serializer.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1"); > > > > // pretty XML output > > > > serializer.setOutputProperty > > > > > > ("{http://xml.apache.org/xslt}indent-amount<http://xml.apache.org/xslt%7Dindent-amount> > ", > > "4"); > > > > > > serializer.setOutputProperty(OutputKeys.INDENT,"yes"); > > > > th.setResult(out); > > > > th.startDocument(); > > > > atts = new AttributesImpl(); > > > > > > th.startElement("","","domains",atts); > > > > } > > > > > > > > public static byte[] sizeOf(Object obj) throws > > java.io.IOException > > > > { > > > > ByteArrayOutputStream byteObject = new > > ByteArrayOutputStream(); > > > > ObjectOutputStream objectOutputStream = new > > ObjectOutputStream(byteObject); > > > > objectOutputStream.writeObject(obj); > > > > objectOutputStream.flush(); > > > > objectOutputStream.close(); > > > > byteObject.close(); > > > > > > > > return byteObject.toByteArray(); > > > > } > > > > > > > > public void process (String s) throws SAXException { > > > > > > > > String [] elements=new String [20]; > > > > elements=s.split("\\: "); > > > > atts.clear(); > > > > > > > > > > > > > > th.startElement("","","domain",atts); > > > > > > > > > > th.startElement("","","domain_name",atts); > > > > > > th.characters(elements[0].toCharArray(),0,elements[0].length()); > > > > > > th.endElement("","","domain_name"); > > > > > > > > > > > > //System.out.println("error"); > > > > > > > > > > th.startElement("","","address",atts); > > > > > > th.characters(elements[1].toCharArray(),0,elements[1].length()); > > > > > > th.endElement("","","address"); > > > > > > > > > > th.startElement("","","server1",atts); > > > > > > th.characters(elements[2].toCharArray(),0,elements[2].length()); > > > > > > th.endElement("","","server1"); > > > > > > > > > > th.startElement("","","server2",atts); > > > > > > th.characters(elements[3].toCharArray(),0,elements[3].length()); > > > > > > th.endElement("","","server2"); > > > > > > > > > > th.startElement("","","owner",atts); > > > > > > th.characters(elements[4].toCharArray(),0,elements[4].length()); > > > > > > th.endElement("","","owner"); > > > > > > > > > > th.startElement("","","owner_email",atts); > > > > > > th.characters(elements[5].toCharArray(),0,elements[5].length()); > > > > > > th.endElement("","","owner_email"); > > > > > > > > > > th.startElement("","","registration_date",atts); > > > > > > th.characters(elements[6].toCharArray(),0,elements[6].length()); > > > > > > th.endElement("","","registration_date"); > > > > > > > > > > th.startElement("","","expiration_date",atts); > > > > > > th.characters(elements[7].toCharArray(),0,elements[7].length()); > > > > > > th.endElement("","","expiration_date"); > > > > > > > > > > th.endElement("","","domain"); > > > > > > > > } > > > > > > > > public void closeXML() throws SAXException { > > > > > > th.endElement("","","domains"); > > > > th.endDocument(); } > > > > } > > > > > > > > > > > > > > > > > > > > > > > > > > > > _______________________________________________ > > > > Linux-programlama mailing list > > > > [email protected] > > > > http://liste.linux.org.tr/mailman/listinfo/linux-programlama > > > > > > > > > > -- > > Anıl KARADAĞ > > Cihan Bilişim A.Ş. - Yazılım Geliştirme Uzmanı > > GYTE- Bilgisayar Müh. Yüksek Lisans öğrencisi > > http://anilkaradag.info/blog > > > > > > > > -----Inline Attachment Follows----- > > > > _______________________________________________ > > Linux-programlama mailing list > > [email protected] > > http://liste.linux.org.tr/mailman/listinfo/linux-programlama > > > > > > _______________________________________________ > Linux-programlama mailing list > [email protected] > http://liste.linux.org.tr/mailman/listinfo/linux-programlama > -- Elvin Şiriyev http://siriyev.net
_______________________________________________ Linux-programlama mailing list [email protected] http://liste.linux.org.tr/mailman/listinfo/linux-programlama
