Problem mit SAX

Status
Nicht offen für weitere Antworten.

spike78

Bekanntes Mitglied
Hallo zusammen,

ich habe ein kleines Speicherproblem mit SAX. Und zwar lese ich eine XML Datei ein und will alle Elemente dieser Datei ein eine HashMap schreiben.

EventMapref.put(event.getEventid(),event);

Nun habe ich aber leider Dateien mit ca. 160000 Elemente und das scheint die gute HashMap nicht zu schaffen. Bei ca. 150000 platzt mir der Speicher. Wie kann ich das lösen ?

Danke und Gruß

Michael
 

KSG9|sebastian

Top Contributor
Du solltest ernsthaft drüber nachdenken ob eine XML-Datei das richtige ist für 160000 Elemente. XML-Dateien sind für "kleinere" Konfigurationsdinge u.s.w. sehr gut, wenn sie aber zu groß werden sind sie sowas von unperformant.
 

spike78

Bekanntes Mitglied
Geht leider nicht. Ich bekomme meine Daten in diesem Format geliefert und muss nun leider damit leben ;(
 

AlArenal

Top Contributor
KSG9|sebastian hat gesagt.:
Du solltest ernsthaft drüber nachdenken ob eine XML-Datei das richtige ist für 160000 Elemente. XML-Dateien sind für "kleinere" Konfigurationsdinge u.s.w. sehr gut, wenn sie aber zu groß werden sind sie sowas von unperformant.

Die ANzahl der Elemente sollte irrelevant sein. Open Office und das neue MS Office nutzen XML-basierte Formate. Die können irhen Kunden wohl kaum sagen, doch bitte nur kleine Excel-Sheets zu erstellen und Word nur noch für kleine Briefe und nicht mehr für Bücher zu benutzen.. ;)
 

KSG9|sebastian

Top Contributor
Ok..elemente ist unglücklich ausgedrückt :)
Wenn die Dateien zu groß werden ist es verdammt langsam. Aber zurück zum Thema:

Wie parst du die Dateien? Wie sehen die Dateien aus?
Bissl code wäre nicht schlecht, und der Stacktrace wär auch ganz nett :)
 

spike78

Bekanntes Mitglied
Also meine XML Datei sieht so aus:

<eventlist>
<event>
<attribute type="AT_----">...</attribute>
<attribute type="AT_----">...</attribute>
.
.
.
</event>

</eventlist>


Hier ein Teil vom Code:

Klasse 1)
Code:
import org.xml.sax.*;
import java.util.HashMap;
import java.util.ArrayList;

public class ZSAXParser extends org.xml.sax.helpers.DefaultHandler
{
    static HashMap EventMapout = new HashMap();
    static HashMap EventMapref = new HashMap();
    static double comAttrCnt;
    private ZEvent event;
    private String value;
    private String compareAttr;
    boolean switchFile;
    private double dummyKeyCnt;
    private String sdummyKeyCnt;
    private  ArrayList list;
    long iCnt;

    public ZSAXParser(String comAttr, boolean switsch){
        compareAttr = comAttr;
        switchFile = switsch;
        comAttrCnt=0;
        dummyKeyCnt =0;
        sdummyKeyCnt="";
    }

    public void startElement( String namespaceURI, String localName,

                              String qName, Attributes atts ) throws SAXException
    {
        int i;

        // Wenn das Element "event" gefunden wird, soll ein neuen Event Objekt erzeugt werden
        if(qName.equals("event")){
            event = new ZEvent(compareAttr);

        }

        // Attributwert setzen
            if(qName.equals("attribute")){
                findcompAttr=event.setKey(atts.getValue( 0 ));
            }
    }

    public void endElement( String namespaceURI, String localName, String qName )
    {
        //Attributende prüfen und Wert setzen
        if(qName.equals("attribute")){
            event.setValue(value);

        }

        // Elementende prüfen
        if(qName.equals("event")){
            event.setEventid();
        
        }
    }

    public void characters(char[] c, int start, int length)    throws SAXException
    {
        value = (new String(c, start, length));
    }

}
------------------------------------------------------------------------------------------------------------------------------

Klasse 2)

Code:
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;


public class ZEvent
{
    private HashMap attributMap;
    private String key, value;
    private String eventid;
    private String comAttribut;
    private double comAttrCnt;

    ZEvent(String comAttr){
        attributMap = new HashMap();
        comAttribut = comAttr;
    }

    private void putEventinMap(){
       attributMap.put(key,value);
       value = null;
    }

    public boolean setKey(String sKey){
       key = sKey;
       if(sKey.equals(comAttribut)){
           comAttrCnt++;
           return true;
       }
       return false;
    }

    public void setValue(String sValue){
       value = sValue;
       putEventinMap();

   }

   public HashMap getattributMap(){
       return attributMap;
   }

   public void setEventid(){
       Iterator it = attributMap.entrySet().iterator();
       while(it.hasNext()){
           Map.Entry entry = (Map.Entry) it.next();
           if(entry.getKey().equals(comAttribut)){
               eventid = (String) entry.getValue();
               break;
           }
       }
   }

  public String getEventid(){
      return eventid;
  }
}
 

huckfinn

Aktives Mitglied
Hi,

1. Kannst du das mal genauer auseinander nehmen!
Wie genau soll die Speicherstrucktur aussehen.
So mal im Pseudocode.

Code:
  ArrayList  event-list of Class Event {

          Event1 of Class {
               Key? 
               HashMap attributes 
         }

          Event2 of Class {
               Key? 
               HashMap attributes 
         }

        .......
     }

Ist das richtig? Ich frage das um raus zu bekommen was ist Key und
was ist Datencontainer.

2. Ich würde bei großen Elementzahlen von der HashMap
absehen ..Bucketing Kollisionen etc. Falls du über einen
Key zugreifen willst ist TreeMap erste Wahl und sucht auch
schneller (AVL-Tree).

3. Was tust du genau hier
Code:
       public void setEventid(){
       Iterator it = attributMap.entrySet().iterator();
       while(it.hasNext()){
           Map.Entry entry = (Map.Entry) it.next();
           if(entry.getKey().equals(comAttribut)){
               eventid = (String) entry.getValue();
               break;
           }
       }
   }

reicht da nicht
Code:
attributMap.get(comAttribut)
?


Als denne Huck
 
Status
Nicht offen für weitere Antworten.
Ähnliche Java Themen
  Titel Forum Antworten Datum
O XPATH Problem - Anfänger XML & JSON 4
so_ein_Komischer Problem mit Clean and Build XML & JSON 1
P JAXB-Problem XML & JSON 1
W Problem mit dem mit XML sortierung XML & JSON 2
S Jaxb Unmarshalling Problem XML & JSON 4
E einfaches Problem XML + XSD + jedit XML & JSON 2
S Xslt Problem XML & JSON 2
B JasperReport Problem in Runtime XML & JSON 2
S Problem with JAXB unmarshalling classes that have the same name in @XmlRootElement XML & JSON 2
R Problem bei: XML und XSL zu HTML XML & JSON 2
M Read / write Problem beim ByteStrom XML & JSON 2
M XML write Problem zweiter Ansatz XML & JSON 3
M XML read Problem XML & JSON 4
M XML write Problem XML & JSON 2
whitenexx Problem beim parsen von Facebook XML XML & JSON 3
M XML Unicode Problem XML & JSON 2
S XJC --> Java-Objects compile Problem XML & JSON 4
F XPath-Problem mit DOM4J XML & JSON 8
B JPA + JAXB Mapping Problem XML & JSON 2
T XPath Problem: finden einer Node nach Attributswert XML & JSON 2
G Problem beim schreiben von XML in eine File XML & JSON 2
S Encoding Problem XML & JSON 7
K JAXB und Maps -> Marshalling-Problem XML & JSON 6
B Problem beim löschen von ChildNodes aus einem XML-DOM XML & JSON 3
E JDOM - Problem beim Zusammenfügen zweier Dateien XML & JSON 2
M JExcelAPI (JXL) Encoding Problem XML & JSON 11
S DOM Parsen Problem mit HTML Sonderzeichen XML & JSON 4
A aus xml --> html Problem XML & JSON 3
Y stax Problem XML & JSON 3
slawaweis Problem mit XSLT (wahrscheinlich ein Bug in Java 6) XML & JSON 16
T Problem beim Parsen von Attribut xmlns="urn:com:test&qu XML & JSON 6
P XPath Problem XML & JSON 2
J Problem beim XML-Lesen XML & JSON 2
M Problem mit FOP in Java Programm XML & JSON 2
S Problem mit XPath XML & JSON 4
J Problem mit compile einer XSD XML & JSON 3
N jdom problem beim lesen von child elementen XML & JSON 5
N problem bei xml lesen mit jdom XML & JSON 2
A XPath Problem XML & JSON 2
W JDOM element ändern funzt nich :( [problem gelöst] XML & JSON 3
G Problem mit XML-Schema Validierung mit Java XML & JSON 12
B jdom: getChildren() problem XML & JSON 4
H XSL-FO Problem mit If XML & JSON 2
loadbrain XPath Problem XML & JSON 2
T addContent / Problem mit Variable XML & JSON 2
F Problem mit JAXB Unmarshaller XML & JSON 2
F JDOM und XPath - Problem mit Namespace ohne Prefix XML & JSON 5
8 SAXParser Problem, startElement wird nicht ausgeführt XML & JSON 2
M Java und XSLT: Performanz-Problem XML & JSON 5
X JDOM SAXBuilder Validationschema - Problem XML & JSON 8
G Problem mit getContent XML & JSON 4
K stax problem XML & JSON 2
A Problem mit JasperReport XML & JSON 6
G DOCTYPE Problem beim Transformer/TransformerFactory etc. XML & JSON 13
C XSD Problem XML & JSON 16
R Problem bei Erstellung von XML(JDOM) XML & JSON 3
R Problem mit SAX-Parser characters() XML & JSON 7
M XPath Problem im Zusammenhang mit document() XML & JSON 2
P Problem beim erstellen eines neuen Elements (JDOM) XML & JSON 5
Z Problem mit getNodeValue() und setNodeValue() in DOM XML & JSON 6
H JAXB CUSTOMIZATION PROBLEM XML & JSON 2
M XPATH und RSS (Problem namespaces) XML & JSON 7
P SAXParser problem? XML & JSON 2
S Problem beim Erstellen eines pdfs XML & JSON 3
V Problem mit xsd XML & JSON 2
P XML mit hilfe von JDOM abspeichern macht Problem XML & JSON 6
G Problem mit addContent() XML & JSON 4
B DTD Problem - Reihenfolge der Einträge XML & JSON 2
R Problem beim Auslesen von Attributen XML & JSON 4
K Problem mit ant/java web services XML & JSON 4
K xml Datei mit JDOM erzeugen, Problem Namespaces XML & JSON 1
P Problem mit XML und DOM XML & JSON 2

Ähnliche Java Themen

Neue Themen


Oben