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]
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
}
}