SAX Parser siehe nichts auf dem Konsole weder eine Fehlermeldung noch eine Ergebnis

Faiza

Mitglied
Hallo zusammen,

ich habe ein Parser SAX geschrieben.Ich kriege keine Fehlermeldung und ich sehe nichts an der Konsole. Was mache ich falsch??
Kann bitte jemand mir weiter Hilfen?


[XML]
<?xml version="1.0" encoding="UTF-8"?>

<OptimISEGuiModel>
<MainButton>
<ChartName>LOC</ChartName>

<charttype value="Cartesian">
<chartrenderer>
<useAlertColors value="true" />
<type value="LineChart" />
<mode value="LineChart" />
</chartrenderer>
</charttype>

<legend>
<visible value="true" />
<position value="right" />
<background value="white" />
<foreground value="" />
</legend>

<labelrenderer>
<color value="" />
<offset value="" />
<rotation value="" />
<visible value="" />
</labelrenderer>

<datasetlegend>
<match value="" />
<display value="Arch" />
<showValue value="true" />
<showStart value="(total: " />
<showEnd value=")" />
</datasetlegend>

<graph>
<name value="Arch" />
<value value="50" />
<color value="0x808080" />
</graph>

<datasetlegend>
<match value="" />
<display value="Other" />
<showValue value="true" />
<showStart value=" (total: " />
<showEnd value=")" />
</datasetlegend>

<graph>
<name value="Other" />
<value value="50" />
<color value="0xCC3333" />
</graph>

<datasetlegend>
<match value="" />
<display value="Model" />
<showValue value="true" />
<showStart value=" (total: " />
<showEnd value=")" />
</datasetlegend>

<graph>
<name value="Model" />
<value value="50" />
<color value="0x0000FF" />
</graph>

<datasetlegend>
<match value="" />
<display value="App" />
<showValue value="true" />
<showStart value=" (total: " />
<showEnd value=")" />
</datasetlegend>


<graph>
<name value="App" />
<value value="50" />
<color value="0x009F6B" />
</graph>

</MainButton>
</OptimISEGuiModel>
[/XML]


Java:
public class MainButton {
	public String getMainButton() {
		return MainButton;
	}

	public String getChartName() {
		return ChartName;
	}

	public String getCharttype() {
		return charttype;
	}

	public String getChartrenderer() {
		return chartrenderer;
	}

	public String getLegend() {
		return legend;
	}

	public String getLabelrenderer() {
		return labelrenderer;
	}

	public String getDatasetlengend() {
		return datasetlengend;
	}

	public String getGraph() {
		return graph;
	}

	public void setMainButton(String mainButton) {
		MainButton = mainButton;
	}

	public void setChartName(String chartName) {
		ChartName = chartName;
	}

	public void setCharttype(String charttype) {
		this.charttype = charttype;
	}

	public void setChartrenderer(String chartrenderer) {
		this.chartrenderer = chartrenderer;
	}

	public void setLegend(String legend) {
		this.legend = legend;
	}

	public void setLabelrenderer(String labelrenderer) {
		this.labelrenderer = labelrenderer;
	}

	public void setDatasetlengend(String datasetlengend) {
		this.datasetlengend = datasetlengend;
	}

	public void setGraph(String graph) {
		this.graph = graph;
	}

	private String MainButton;
	private String ChartName;
	private String charttype;
	private String chartrenderer;
	private String legend;
	private String labelrenderer;
	private String datasetlengend;
	private String graph;
	

////////////////////////////////////////////
	public class Charttype{
		
		public Charttype(){
				this.charttype= charttype;

		}
		public String getCharttype() {
			return charttype;
		}

		public void setCharttype(String charttype) {
			this.charttype = charttype;
		}

		private String charttype;
	
////////////////////////////////////////////

		public class Chartrenderer{
			
			public Chartrenderer(){
				this.useAlertColors = useAlertColors;
				this.type = type;
				this.mode = mode;
			}
		
			public String getUseAlertColors() {
				return useAlertColors;
			}
			public String getType() {
				return type;
			}
			public String getMode() {
				return mode;
			}
			public void setUseAlertColors(String useAlertColors) {
				this.useAlertColors = useAlertColors;
			}
			public void setType(String type) {
				this.type = type;
			}
			public void setMode(String mode) {
				this.mode = mode;
			}
			private String useAlertColors;
			private String type;
			private String mode;
			
			public String toString(){
				return this.useAlertColors + "\n" + this.type + "\n" + this.mode;
			}
		}
		
		public String toString(){
			return this.charttype;
		}
	}
////////////////////////////////////////////
	public class legend{
		
		public legend(){
			this.visible = visible;
			this.position = position;
			this.background = background;
			this.forground = forground;
		}
		public String getVisible() {
			return visible;
		}
		public String getPosition() {
			return position;
		}
		public String getBackground() {
			return background;
		}
		public String getForground() {
			return forground;
		}
		public void setVisible(String visible) {
			this.visible = visible;
		}
		public void setPosition(String position) {
			this.position = position;
		}
		public void setBackground(String background) {
			this.background = background;
		}
		public void setForground(String forground) {
			this.forground = forground;
		}
		private String visible;
		private String position;
		private String background;
		private String forground;
		
		public String toString(){
			return this.visible + "\n" + this.position + "\n" + this.background + "\n" + this.forground;
		}
		
		
	}
////////////////////////////////////////////

	public class labelrenderer{
		
		public labelrenderer(){
			this.color = color;
			this.offset = offset;
			this.rotation = rotation;
			this.visible = visible;
		}
		public String getColor() {
			return color;
		}
		public String getOffset() {
			return offset;
		}
		public int getRotation() {
			return rotation;
		}
		public String getVisible() {
			return visible;
		}
		public void setColor(String color) {
			this.color = color;
		}
		public void setOffset(String offset) {
			this.offset = offset;
		}
		public void setRotation(int rotation) {
			this.rotation = rotation;
		}
		public void setVisible(String visible) {
			this.visible = visible;
		}
		private String color;
		private String offset;
		private int rotation;
		private String visible;
		
		
		public String toString(){
			return this.color +"\n"+ this.offset +"\n"+ this.rotation +"\n"+ this.visible;
		}
	}
////////////////////////////////////////////

	public class datasetlegend{  // this is a list which repeats itself manytime unter Mainbutton
		
		public datasetlegend(){
			this.match = match;
			this.display = display;
			this.showValue = showValue;
			this.StartValue = StartValue;
			this.showEnd = showEnd;
		}
		
		public String getMatch() {
			return match;
		}
		public String getDisplay() {
			return display;
		}
		public String getShowValue() {
			return showValue;
		}
		public String getStartValue() {
			return StartValue;
		}
		public String getShowEnd() {
			return showEnd;
		}
		public void setMatch(String match) {
			this.match = match;
		}
		public void setDisplay(String display) {
			this.display = display;
		}
		public void setShowValue(String showValue) {
			this.showValue = showValue;
		}
		public void setStartValue(String startValue) {
			StartValue = startValue;
		}
		public void setShowEnd(String showEnd) {
			this.showEnd = showEnd;
		}
		private String match;
		private String display;
		private String showValue;
		private String StartValue;
		private String showEnd;
		
		public String toString(){
			return this.match + "\n" + this.display + "\n" + this.showValue + "\n" + this.StartValue + "\n" + this.showEnd;
		}
	}
////////////////////////////////////////////

	public class graph{		// this is a list which repeats itself manytime unter Mainbutton
		
		public graph(){
			
			this.name = name;
			this.value = value;
			this.color = color;
		}
		public String getName() {
			return name;
		}
		public String getValue() {
			return value;
		}
		public String getColor() {
			return color;
		}
		public void setName(String name) {
			this.name = name;
		}
		public void setValue(String value) {
			this.value = value;
		}
		public void setColor(String color) {
			this.color = color;
		}
		private String name;
		private String value;
		private String color;
		public String toString(){
			return this.name +"\n"+ this.value +"\n"+ this.color;
		}
	}
	
	public String toString(){
		StringBuffer sb = new StringBuffer();
		sb.append("ChartName:" + getChartName());
		sb.append("ChartType:" + getCharttype());
		sb.append("Chartrenderer:" + getChartrenderer());
		sb.append("Legend: " + getLegend());
		sb.append("Labelrenderer:" + getLabelrenderer());
		sb.append("DatasetLegend:" + getDatasetlengend());
		sb.append("graph:" + getGraph());
		
		
		return ChartName + chartrenderer + charttype + datasetlengend + graph + labelrenderer + legend + MainButton;			
	}

	
}


Java:
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;

public class GuiMain {

	/**
	 * @param args
	 * @throws Exception
	 */
	public static void main(String[] argv) throws Exception {

//	     OptWindow optwin = new OptWindow();
//         optwin.run();
		try {

			// XMLReader erzeugen
			XMLReader xmlReader = XMLReaderFactory.createXMLReader();
			// Pfad zur XML Datei
			FileReader reader = new FileReader("OptGuiModel.xml");
			InputSource inputSource = new InputSource(reader);
			// PersonenContentHandler wird übergeben
			xmlReader.setContentHandler(new VariableContentHandler());
			// Parsen wird gestartet
			xmlReader.parse(inputSource);
			
			
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (SAXException e) {
			e.printStackTrace();
		}

	}
}


Java:
import java.util.ArrayList;

import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;


public class VariableContentHandler implements ContentHandler {
	
	private ArrayList<MainButton> allComponent = new ArrayList<MainButton>();
	private String actualValue;
	private MainButton mainButton;
	
	// actualValue die eingelsen wird, soll in eine Zwischenvariable gespeichert werden
	public void characters(char[] ch, int start, int length) throws SAXException {
	actualValue = new String(ch,start,length);
	}

	 // Methode wird aufgerufen wenn der Parser zu einem Start-Tag kommt
	 public void startElement(String uri, String localName, String qName,
		      Attributes atts) throws SAXException {
		 if(localName.equals("MainButton"));
	      // Neue component erzeugen
		 mainButton = new MainButton();
	}
	
	 
	// Methode wird aufgerufen wenn der Parser zu einem End-Tag kommt
	  public void endElement(String uri, String localName, String qName)
	      throws SAXException {
		  
		  if(localName.equals("ChartName")){
			  mainButton.setChartName(actualValue);
		  }

		  if(localName.equals("charttype")){
				 mainButton.setCharttype(actualValue);
				}
		  if(localName.equals("chartrenderer")){
			  mainButton.setChartrenderer(actualValue);
			  
			  // ich will die weitere elemente hier ausgeben wieso kann ich hier nicht zugreifen???
		  }

		  if(localName.equals("legend")){
			  mainButton.setLegend(actualValue);
		  }

		  if(localName.equals("labelrenderer")){
			  mainButton.setLabelrenderer(actualValue);
		  }

		  if(localName.equals("datasetlegend")){
			  mainButton.setDatasetlengend(actualValue);
		  }
		  
		  if(localName.equals("graph")){
			  mainButton.setGraph(actualValue);
		  }
		  
		  if(localName.equals("datasetlegend")){
			  mainButton.setDatasetlengend(actualValue);
		  }
	  }
	
	
	public void endDocument() throws SAXException {
		
	}

	@Override
	public void endPrefixMapping(String arg0) throws SAXException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void ignorableWhitespace(char[] arg0, int arg1, int arg2)
			throws SAXException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void processingInstruction(String arg0, String arg1)
			throws SAXException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void setDocumentLocator(Locator arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void skippedEntity(String arg0) throws SAXException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void startDocument() throws SAXException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void startPrefixMapping(String arg0, String arg1)
			throws SAXException {
		// TODO Auto-generated method stub
		
	}

}
 
S

SlaterB

Gast
wenn ich dein Programm 1:1 kopiere passiert bei mir auch exakt nichts, aber was soll schon passieren?
nirgendwo steht System.out.println() oder sonst etwas was irgendwie Auswirkung hätte (format c: )

eine GUI wird auch nicht gestartet, nix,

wenn du in deinen Parser in jede Methode erstmal eine Ausgabe der übergebenen Parameter einbaust, dann passiert dagegen ne Menge
 

Faiza

Mitglied
hmm komisch... in meine MainButton.java habe ich

Java:
	public String toString(){
		StringBuffer sb = new StringBuffer();
		sb.append("ChartName:" + getChartName());
		sb.append("ChartType:" + getCharttype());
		sb.append("Chartrenderer:" + getChartrenderer());
		sb.append("Legend: " + getLegend());
		sb.append("Labelrenderer:" + getLabelrenderer());
		sb.append("DatasetLegend:" + getDatasetlengend());
		sb.append("graph:" + getGraph());
		
		
		return ChartName + chartrenderer + charttype + datasetlengend + graph + labelrenderer + legend + MainButton;


schon alleine dadurch soll doch irgendwas ausgegeben werden oder bin ich jetzt total blöd...
 
S

SlaterB

Gast
du erzeugst einen String, ein Java-Objekt, das an und für sich still und heimlich im Speicher sitzt,
meist Tausende gleichzeitig, sei froh dass die sich nicht alle von alleine melden..,
erst mit
[c]System.out.println("Test");[/c]
oder
[c]System.out.println(object.toString()); // .toString() kann hier auch entfallen[/c]
passiert etwas
 

Faiza

Mitglied
tut mir echt Leid, wenn ich mich blöd anstelle aber ich bin sehr sehr neu in Java überhaupt.
Leider muss ich diese Aufgaben dringend erledigen und habe Lücken in meine Kenntnisse.
Kannst du bitte bitte eine konkrete Beispiel geben?
Ich habe jetzt das hier versucht und es spuckt mir alles aus aber ich möchte nur einzelne Elemente

Java:
// Methode wird aufgerufen wenn der Parser zu einem Start-Tag kommt
	 public void startElement(String uri, String localName, String qName,
		      Attributes atts) throws SAXException {
		 
		 if(localName.equals("ChartName"));
		 System.out.println(localName);		 
	 }


Code:
OptimISEGuiModel
MainButton
ChartName
charttype
chartrenderer
useAlertColors
type
mode
legend
visible
position  
...
...
etc.
 
S

SlaterB

Gast
das ; am Ende der if-Zeile weg, und als Anfänger besser immer Klammern verwenden

Java:
if (x) { 
  y; 
}
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
pkm Gibt es XML-Parser-Bibliotheken XML & JSON 3
B XML-Daten mit SAX Parser verarbeiten in Java XML & JSON 4
MiMa SAX-Parser beenden? XML & JSON 5
K GSON-Parser XML & JSON 6
K XML-Parser vs. XLST XML & JSON 4
L DOM Parser Implementieren XML & JSON 9
M SAX Parser implementieren XML & JSON 2
E Gibt es denn einen XML-Parser für JUnit-Tests? XML & JSON 6
D XSD Parser XML & JSON 1
T Neuer XML Parser!!! XML & JSON 33
J XML Parser anhand xsd erzeugen XML & JSON 2
H SAX Parser optimieren XML & JSON 5
H Sax Parser verschluckt teile XML & JSON 11
C XML SAX Parser XML & JSON 10
R Handler-Wechsel, SAX Parser bricht nach 8192 Byte ab XML & JSON 5
B SAX-Parser - Dokumente einlesen und in einer Map ablegen XML & JSON 2
S Sax Parser Performance XML & JSON 2
M Eigener XML-Parser XML & JSON 1
S Typsicherer HTML-Parser XML & JSON 5
S HTML Parser XML & JSON 2
B Parser und Fabrik XML & JSON 6
enne87 SAX-Parser XML & JSON 5
C Mit SAX Parser XML Attribute auswerten XML & JSON 3
H XML-Parser: geparste Strings in Konstruktor? XML & JSON 9
S DOM Parser XML & JSON 12
S Sax Parser XML & JSON 3
D Speicherüberlauf bei character-Methode mit SAX-Parser XML & JSON 3
Y Welchen XML Parser / Klassen aus XSD generieren lassen XML & JSON 4
H Brauche ich einen speziellen XML-Parser? XML & JSON 2
M Unhierarchisches XML-File mit DOM-Parser auswerten XML & JSON 5
G XML Parser Fehler, zwei gleiche kind-Elemente XML & JSON 7
S Welcher XML-Parser am besten? XML & JSON 4
S Parser XML & JSON 2
S JAVA XML Parser der einen String parst XML & JSON 3
Noar XML-Parser mit GUI? XML & JSON 2
R Problem mit SAX-Parser characters() XML & JSON 7
K SAX Parser Character Puffer zu klein XML & JSON 2
B Mit Sax-Parser validieren XML & JSON 7
Wildcard xpath Parser XML & JSON 8

Ähnliche Java Themen

Neue Themen


Oben