Hallo zusammen,
ich sitze hier seit vier Stunden und suche meine Fehler, aber ich sehe ihn echt nicht.:rtfm:
ich möchte meine Attribute basetype, type, position und mode auslesen, schaffe ich aber nicht. Die restliche habe ich schon. Könntet ihr BITTE BITTE drüber gucken???
Vielen Dank für eure helfe im voraus!!!
[XML]<?xml version="1.0" encoding="UTF-8"?>
<OptimISEGuiModel>
<MainButton>
<ChartName>LOC</ChartName>
<charttype basetype="Cartesian">
<chartrenderer useAlertColors="true" type="LineChart" mode="LineChart"> </chartrenderer></charttype>
<legend visible="true" position="right" background="white" foreground="" />
<labelrenderer color="" offset= "" rotation= "" visible=""/>
<datasetlegend match="" display="Arch" showValue="true" showStart=" (total: " showEnd=")"/>
<graph name="Arch" value="50" color="0x808080"/>
<datasetlegend match="" display="Other" showValue="true" showStart= " (total: " showEnd=")" />
<graph name="Other" value="50" color="0xCC3333"/>
<datasetlegend match="" display="Model" showValue="true" showStart=" (total: " showEnd=")"/>
<graph name="Model" value="50" color="0x0000FF"/>
<datasetlegend match="" display="App" showValue="true" showStart=" (total: " showEnd=")" />
<graph name="App" value="50" color="0x009F6B"/>
</MainButton>
<MainButton>
<!-- Sir Statistics Window -->
<ChartName>Sir Statistics</ChartName>
<charttype basetype="Cartesian">
<chartrenderer useAlertColors="true" type="BarChart" mode="BarChart"> </chartrenderer></charttype>
<legend visible="true" position="right" background="white" foreground=""/>
</MainButton>
<MainButton>
<!-- Test Statistics Window -->
<ChartName>Test Statistics</ChartName>
<charttype basetype="Cartesian">
<chartrenderer useAlertColors="true" type="LineChart" mode="LineChart"> </chartrenderer></charttype>
<legend visible="true" position="right" background="white" foreground=""/>
</MainButton>
<MainButton>
<!-- Issue Window -->
<ChartName>Issue Overview</ChartName>
<charttype basetype="Cartesian">
<chartrenderer useAlertColors="true" type="BarChart" mode="BarChart"> </chartrenderer></charttype>
<legend visible="true" position="right" background="white" foreground=""/>
</MainButton>
<MainButton>
<ChartName>Rappidd</ChartName>
<!-- Rappidd Window -->
<charttype basetype="Cartesian">
<chartrenderer useAlertColors="true" type="BarChart" mode="BarChart"> </chartrenderer></charttype>
<legend visible="true" position="right" background="white" foreground=""/>
</MainButton>
</OptimISEGuiModel>
[/XML]
ich sitze hier seit vier Stunden und suche meine Fehler, aber ich sehe ihn echt nicht.:rtfm:
ich möchte meine Attribute basetype, type, position und mode auslesen, schaffe ich aber nicht. Die restliche habe ich schon. Könntet ihr BITTE BITTE drüber gucken???
Vielen Dank für eure helfe im voraus!!!
Java:
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
public class OptWindow {
ArrayList<VariableHandler> component;
Document dom;
public OptWindow() {
// create a list to hold the Element objects
component = new ArrayList<VariableHandler>();
}
public void run() {
// parse the xml file and get the dom object
parseXmlFile();
// get each component element and create a component object
parseDocument();
// Iterate through the list and print the data
printData();
}
private void parseXmlFile() {
// get the factory
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
// Using factory get an instance of document builder
DocumentBuilder db = dbf.newDocumentBuilder();
// parse using builder to get DOM representation of the XML file
dom = db.parse("OptimISEGuiModel.xml");
} catch (ParserConfigurationException pce) {
pce.printStackTrace();
} catch (SAXException se) {
se.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
private void parseDocument() {
//get the root elememt
Element docEle = dom.getDocumentElement();
//get a nodelist of <component> elements
NodeList nl = docEle.getElementsByTagName("MainButton");
if(nl != null && nl.getLength() > 0) {
for(int i = 0 ; i < nl.getLength();i++) {
//get the component element
Element el = (Element)nl.item(i);
//get the component object
VariableHandler var = getOptComponent(el);
//add it to list
component.add(var);
}
}
}
private VariableHandler getOptComponent(Element cp) {
//for each <component> element get text or int or char values of
String ChartName = getTextValue(cp,"ChartName");
String basetype = cp.getAttribute("basetype");
boolean useAlertColors = cp.getAttribute("useAlertColors") != null;
String type = cp.getAttribute("type");
String mode = cp.getAttribute("mode");
//legend config
boolean visible= cp.getAttribute("visible") != null;
String position = getTextValue(cp, "position");
//Create a new Component element with the value read from the xml nodes
VariableHandler e = new VariableHandler(ChartName,basetype,useAlertColors,type,
mode,visible,position);
return e;
}
private String getTextValue(Element ele, String tagName) {
String textVal = null;
NodeList nl = ele.getElementsByTagName(tagName);
if(nl != null && nl.getLength() > 0) {
Element el = (Element)nl.item(0);
textVal = el.getFirstChild().getNodeValue();
}
return textVal;
}
@SuppressWarnings("unused")
private int getIntValue(Element ele, String tagName) {
//in production application you would catch the exception
return Integer.parseInt(getTextValue(ele,tagName));
}
private void printData() {
System.out.println("No of MainButton'" + component.size() + "'."
+ "\n" +"MainButton Details: ");
Iterator<VariableHandler> it = component.iterator();
while(it.hasNext()) {
System.out.println(it.next().toString());
}
}
public static void main(String[] args){
//create an instance
OptWindow optwin = new OptWindow();
//call run
optwin.run();
}
}
Java:
public class VariableHandler {
public String getPosition() {
return position;
}
public void setPosition(String position) {
this.position = position;
}
public boolean isVisible() {
return visible;
}
public void setVisible(boolean visible) {
this.visible = visible;
}
public String getChartName() {
return ChartName;
}
public String getBasetype() {
return basetype;
}
public boolean isUseAlertColors() {
return useAlertColors;
}
public String getType() {
return type;
}
public String getMode() {
return mode;
}
public void setChartName(String chartName) {
ChartName = chartName;
}
public void setBasetype(String basetype) {
this.basetype = basetype;
}
public void setUseAlertColors(boolean useAlertColors) {
this.useAlertColors = useAlertColors;
}
public void setType(String type) {
this.type = type;
}
public void setMode(String mode) {
this.mode = mode;
}
private String ChartName;
private String basetype;
private boolean useAlertColors;
private String type;
private String mode;
private boolean visible;
private String position;
public VariableHandler(){
}
public VariableHandler( String ChartName,String basetype, boolean useAlertColors,
String type, String mode, boolean visible, String position) {
this.ChartName = ChartName;
this.basetype = basetype;
this.useAlertColors = useAlertColors;
this.type = type;
this.mode = mode;
this.visible = visible;
this.position = position;
}
/**
* Test Area
*/
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append("ChartName:" + getChartName());
sb.append("\n");
sb.append("basetype: " + getBasetype());
sb.append("\n");
sb.append("useAlertColors: " + isUseAlertColors());
sb.append("\n");
sb.append("type: " + getType());
sb.append("\n");
sb.append("mode: " + getMode());
sb.append("\n");
sb.append("visible: " + isVisible());
sb.append("\n");
sb.append("positon: " + getPosition());
sb.append("\n");
return sb.toString();
}
}
[XML]<?xml version="1.0" encoding="UTF-8"?>
<OptimISEGuiModel>
<MainButton>
<ChartName>LOC</ChartName>
<charttype basetype="Cartesian">
<chartrenderer useAlertColors="true" type="LineChart" mode="LineChart"> </chartrenderer></charttype>
<legend visible="true" position="right" background="white" foreground="" />
<labelrenderer color="" offset= "" rotation= "" visible=""/>
<datasetlegend match="" display="Arch" showValue="true" showStart=" (total: " showEnd=")"/>
<graph name="Arch" value="50" color="0x808080"/>
<datasetlegend match="" display="Other" showValue="true" showStart= " (total: " showEnd=")" />
<graph name="Other" value="50" color="0xCC3333"/>
<datasetlegend match="" display="Model" showValue="true" showStart=" (total: " showEnd=")"/>
<graph name="Model" value="50" color="0x0000FF"/>
<datasetlegend match="" display="App" showValue="true" showStart=" (total: " showEnd=")" />
<graph name="App" value="50" color="0x009F6B"/>
</MainButton>
<MainButton>
<!-- Sir Statistics Window -->
<ChartName>Sir Statistics</ChartName>
<charttype basetype="Cartesian">
<chartrenderer useAlertColors="true" type="BarChart" mode="BarChart"> </chartrenderer></charttype>
<legend visible="true" position="right" background="white" foreground=""/>
</MainButton>
<MainButton>
<!-- Test Statistics Window -->
<ChartName>Test Statistics</ChartName>
<charttype basetype="Cartesian">
<chartrenderer useAlertColors="true" type="LineChart" mode="LineChart"> </chartrenderer></charttype>
<legend visible="true" position="right" background="white" foreground=""/>
</MainButton>
<MainButton>
<!-- Issue Window -->
<ChartName>Issue Overview</ChartName>
<charttype basetype="Cartesian">
<chartrenderer useAlertColors="true" type="BarChart" mode="BarChart"> </chartrenderer></charttype>
<legend visible="true" position="right" background="white" foreground=""/>
</MainButton>
<MainButton>
<ChartName>Rappidd</ChartName>
<!-- Rappidd Window -->
<charttype basetype="Cartesian">
<chartrenderer useAlertColors="true" type="BarChart" mode="BarChart"> </chartrenderer></charttype>
<legend visible="true" position="right" background="white" foreground=""/>
</MainButton>
</OptimISEGuiModel>
[/XML]