XML File

Status
Nicht offen für weitere Antworten.

Titanpharao

Bekanntes Mitglied
Hi hat mal einer zufälligerweise eine riesen XML Datei?

Am besten mit über 1000 Zeilen, oder noch größer.

Muss mein Programm testen, aber finde! auch bei google keine.
Plz mal linken, nicht posten^^
 
Hm...habe mal alle durchprobiert..
Also das programm arbeitet die sehr schnell ab ;-)

Nur ich brauche Datein mit vielen Tags. Das Programm zeigt einen Baum an aus einer XML-Datei mit allen seinen Tags ohne Einträge. Am Ende soll man sich die Tags zusammenklicken und es wird eine neue XML-Datei erstellt.

Aber die Datein haben meistens nur 4-5 und dann 100 x Cityname.

Bräuchte eher sowas in der Art.

Kontinent
Land
Stadt
etc etc..
 
Z.B. so:
Code:
import java.io.FileOutputStream;
import java.io.OutputStream;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class XMLGen {
	
	private final int count;
	private final int depth;
	private Document dom;
	
	
	public XMLGen()  {
		this( 4, 4);
	}

	public XMLGen( final int count, final int depth)  {
		this.count = count;
		this.depth = depth; 
	}
	
	
	public Document getDOM() throws ParserConfigurationException {
		if ( dom == null) dom = createDOM();
		return dom;
	}
	
	
	private Document createDOM() throws ParserConfigurationException {
		
		Document d = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
		d.appendChild( d.createElement( "root"));
		appendChildNodes( d.getDocumentElement(), 0);
		return d;
	}
	
	private void appendChildNodes( Element e, int lvl) { 
		
		for ( int i=0; i<count; i++) {
			Element c = e.getOwnerDocument().createElement( "tag" + i + "_" + lvl);
			e.appendChild( c);
			if ( lvl <= depth) appendChildNodes( c, lvl+1);
		}	
	}
	
	public static void output( Document doc, OutputStream out) throws TransformerException {
		Transformer trans = TransformerFactory.newInstance().newTransformer();
		trans.setOutputProperty( OutputKeys.OMIT_XML_DECLARATION, "no");
		trans.setOutputProperty( OutputKeys.INDENT, "yes");
		trans.setOutputProperty( OutputKeys.STANDALONE, "yes");
		trans.setOutputProperty( OutputKeys.ENCODING, "ISO-8859-1");
		trans.setOutputProperty( OutputKeys.METHOD, "xml");
		DOMSource src = new DOMSource( doc);
		trans.transform( src, new StreamResult( out));
	}
	
	public static void main( String[] args) throws Exception {
		
		XMLGen xg = new XMLGen();
		output( xg.getDOM(), new FileOutputStream( "file.xml"));
		
	}
}
 
Titanpharao hat gesagt.:
Die ist echt ma l riesig

Das kannst du durch Verändern der Paramter für depth und count ja noch ändern. Da das aber rekursiv programmiert ist, sollte insbesondere depth nicht zu hoch sein, sonst läuft der STack über :wink:
 
Hm...komisch wenn ich eine 6x6 große datei erstellen will(oder besser größer) steigt der aus.

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.lang.StringBuilder.toString(Unknown Source)
at trees.XMLGen.appendChildNodes(XMLGen.java:52)

Ist im Hauptspeicher so schon 100MB groß.

Wobei ist egal...mein Programm kann eh nicht 4m einträge Verarbeiten^^
 
Status
Nicht offen für weitere Antworten.

Neue Themen


Zurück
Oben