Kód:
NodeList vertexes = doc.getElementsByTagName("Vertex");
List<Text> texts = new ArrayList<Text>();
for (int s = 0; s < vertexes.getLength(); s++) {
Node fstNode = vertexes.item(s);
if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
Element fstElmnt = (Element) fstNode;
NodeList nodename = fstElmnt.getElementsByTagName("Name");
NodeList nodeid = fstElmnt.getElementsByTagName("Id");
NodeList nodeisinput = fstElmnt.getElementsByTagName("IsInput");
NodeList nodeisoutput = fstElmnt.getElementsByTagName("IsOutput");
Element nameelement = (Element) nodename.item(0);
NodeList fstNm = nameelement.getChildNodes();
Element idelement = (Element) nodeid.item(0);
NodeList fstNm2 = idelement.getChildNodes();
Element inputelement = (Element) nodeisinput.item(0);
NodeList fstNm3 = inputelement.getChildNodes();
Element outputelement = (Element) nodeisoutput.item(0);
NodeList fstNm4 = outputelement.getChildNodes();
String vertexname;
if (fstNm.item(0) == null) {
vertexname = "";
} else {
vertexname = ((Node) fstNm.item(0)).getNodeValue();
}
int vertexid = Integer.parseInt(((Node) fstNm2.item(0)).getNodeValue());
boolean vertexinpt = Boolean.parseBoolean(((Node) fstNm3.item(0)).getNodeValue());
boolean vertexoupt = Boolean.parseBoolean(((Node) fstNm4.item(0)).getNodeValue());
// System.out.println("ID "+vertexoupt);
NodeList vertextexts = fstElmnt.getElementsByTagName("Vertex_Text");
for (int i = 0; i < vertextexts.getLength(); i++) {
Node bla = vertextexts.item(i);
if (bla.getNodeType() == Node.ELEMENT_NODE) {
Element elmtext = (Element) bla;
String textid = elmtext.getAttribute("Id");
String textcount = elmtext.getAttribute("Count");
Text text = new Text(Integer.parseInt(textid), Integer.parseInt(textcount));
texts.add(text);
}
}
Vertex vertex = new Vertex(vertexid, vertexname, vertexinpt, vertexinpt, texts );
System.out.println(vertex);
ptfsvertexes.add(vertex);
texts.clear();
System.out.println(vertex);
}
}
zdravim... takze problem je takyto.. nacitavam veci z XML a ako vidite na konci si vytvaram novy objekt vertex kde priradujem list textov
texts... potom si tento vertex pridam este aj do arraylistu vertexov.. a texts vyprazdnim pre dalsie nacitavanie...
lenze vystup je takyto
Kód:
ID: 1, Name: , isInput: true, isOutput: true, texts: [ID: 1, Count: 0, ID: 2, Count: 0, ID: 3, Count: 1, ID: 4, Count: 1, ID: 5, Count: 0, ID: 6, Count: 0]
ID: 1, Name: , isInput: true, isOutput: true, texts: []
ID: 2, Name: t1, isInput: false, isOutput: false, texts: []
ID: 2, Name: t1, isInput: false, isOutput: false, texts: []
ID: 3, Name: t2, isInput: false, isOutput: false, texts: []
ID: 3, Name: t2, isInput: false, isOutput: false, texts: []
ID: 5, Name: t4, isInput: false, isOutput: false, texts: []
ID: 5, Name: t4, isInput: false, isOutput: false, texts: []
ID: 6, Name: t3, isInput: false, isOutput: false, texts: []
ID: 6, Name: t3, isInput: false, isOutput: false, texts: []
[b]ID: 7, Name: , isInput: false, isOutput: false, texts: [ID: 1, Count: 1, ID: 2, Count: 1, ID: 3, Count: 0, ID: 4, Count: 1, ID: 5, Count: 0, ID: 6, Count: 0]
ID: 7, Name: , isInput: false, isOutput: false, texts: [][/b]
ID: 8, Name: t3, isInput: false, isOutput: false, texts: []
ID: 8, Name: t3, isInput: false, isOutput: false, texts: []
takze otazka je... preco si mi zmaze aj list textov v objekte vertex? Za odpovede dakujem.