public static void deleteMovie(Document doc, String personName)
{
NodeList nodes = doc.getFirstChild().getChildNodes();
for (int i = 0; i < nodes.getLength(); i++)
{
if(nodes.item(i).getNodeName().equals(STR_RETURN_TEXT))
{
continue;
}
if(nodes.item(i).getAttributes().item(0).getTextContent().equals(personName))
{
doc.getFirstChild().removeChild(nodes.item(i));
}
}
}
Code:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<MovieDB>
<Movie id="1">
<titel>Titanic1</titel>
<genre>Drama, Romance</genre>
<jahr>1997</jahr>
<schauspieler>Leonardo DiCaprio, Kate Winslet, Billy Zane, Kathy Bates</schauspieler>
<handlung>A seventeen-year-old aristocrat, expecting to be married to a rich claimant by her mother, falls in love with a kind but poor artist aboard the luxurious, ill-fated R.M.S. Titanic.</handlung>
<dauer>194 min</dauer>
</Movie>
<Movie id="2">
<titel>Titanic2</titel>
<genre>Drama, Romance</genre>
<jahr>1997</jahr>
<schauspieler>Leonardo DiCaprio, Kate Winslet, Billy Zane, Kathy Bates</schauspieler>
<handlung>A seventeen-year-old aristocrat, expecting to be married to a rich claimant by her mother, falls in love with a kind but poor artist aboard the luxurious, ill-fated R.M.S. Titanic.</handlung>
<dauer>194 min</dauer>
</Movie>
<Movie id="3">
<titel>Titanic3</titel>
<genre>Drama, Romance</genre>
<jahr>1997</jahr>
<schauspieler>Leonardo DiCaprio, Kate Winslet, Billy Zane, Kathy Bates</schauspieler>
<handlung>A seventeen-year-old aristocrat, expecting to be married to a rich claimant by her mother, falls in love with a kind but poor artist aboard the luxurious, ill-fated R.M.S. Titanic.</handlung>
<dauer>194 min</dauer>
</Movie>
<Movie id="4">
<titel>Titanic4</titel>
<genre>Drama, Romance</genre>
<jahr>1997</jahr>
<schauspieler>Leonardo DiCaprio, Kate Winslet, Billy Zane, Kathy Bates</schauspieler>
<handlung>A seventeen-year-old aristocrat, expecting to be married to a rich claimant by her mother, falls in love with a kind but poor artist aboard the luxurious, ill-fated R.M.S. Titanic.</handlung>
<dauer>194 min</dauer>
</Movie>
<Movie id="5">
<titel>Titanic5</titel>
<genre>Drama, Romance</genre>
<jahr>1997</jahr>
<schauspieler>Leonardo DiCaprio, Kate Winslet, Billy Zane, Kathy Bates</schauspieler>
<handlung>A seventeen-year-old aristocrat, expecting to be married to a rich claimant by her mother, falls in love with a kind but poor artist aboard the luxurious, ill-fated R.M.S. Titanic.</handlung>
<dauer>194 min</dauer>
</Movie>
</MovieDB>
Der Java-Algorithmus oben löscht aus der XML Datei einen Film komplett heraus jedoch liegt das Problem dabei, dass die Attribute von "Movie" nicht mitgeändert werden heißt:
vor dem löschen: 1,2,3,4,5
nach dem löschen von 3: 1,2,4,5
Soll aber so aussehen: 1,2,3,4
Welchen Wert hat deine Variable i in deinem Ansatz?
Stell sicher dass du von 0 Anfängst.
Code:
public void updateIdAttribute(Document doc) {
NodeList movie = doc.getElementsByTagName("Movie");
Element elm = null;
for(int i = 0; i < movie.getLength(); i++) {
elm = (Element) movie.item(i);
elm.setAttribute("id", "" + i);
}
}
Welchen Wert hat deine Variable i in deinem Ansatz?
Stell sicher dass du von 0 Anfängst.
Der Ansatz ist eine Ergänzung zu dem obrigen Quelltext:
Code:
public static void deleteMovie(Document doc, String personName)
{
NodeList nodes = doc.getFirstChild().getChildNodes();
for (int i = 0; i < nodes.getLength(); i++)
{
if(nodes.item(i).getNodeName().equals(STR_RETURN_TEXT))
{
continue;
}
if(nodes.item(i).getAttributes().item(0).getTextContent().equals(personName))
{
doc.getFirstChild().removeChild(nodes.item(i));
NodeList movies = doc.getElementsByTagName("Movie");
Element emp = null;
for(int j = i; j < movies.getLength(); j++)
{
emp = (Element) movies.item(j);
emp.setAttribute("id", String.valueOf(j));
}
}
}
}
Quote:
Originally Posted by XxharCs
Code:
public void updateIdAttribute(Document doc) {
NodeList movie = doc.getElementsByTagName("Movie");
Element elm = null;
for(int i = 0; i < movie.getLength(); i ++) {
elm = (Element) movie.item(i);
elm.setAttribute("id", "" + i);
}
}
[Java] Datei erstellt, wenn sie bereits existiert dann umbennen 01/16/2014 - General Coding - 2 Replies Hey Leute,
also ich habe folgenden Code
int zahl = 1;
File imageFile = new File("screenshot" + zahl + ".png");
ImageIO.write(bufferedImage, "png", imageFile);
Attribut - Meisterschaft 10/11/2012 - World of Warcraft - 2 Replies Was bewirkt Meisterschaft genau? Ich hab das noch nicht ganz verstanden. (Lange WoW Pause)
Bei Google habe ich nur das hier gefunden, aber so ganz beantwortet das nicht meine Frage...
Meisterschaft – Hierbei handelt es sich um einen neuen Wert, der den Spielern erlauben wird sich in der Sache zu verbessern, die den gewählten Talentbaum cool oder einzigartig macht. Er ist direkt an die Talente gebunden. Was ihr also erhaltet, wenn ihr diesen Wert erhöht, hängt ganz von eurer Klasse und der...
[TuT] +3 > +10 Effekt + Attribut 07/17/2008 - Flyff - 40 Replies So da ich ja schon in einem anderen Post geschrieben hatte, das ich mich an die Arbeit machen werden und herausfinden werde wie man sein Set leuchten (glow) von +3, +4 etc. auf +10 machen kann, habe dazu noch herausgefunden wie man Attribute die auf der waffe sind (muss mindestens +4 sein) wie man die auch ganz einfach auf +10 erweitern kann.
Ihr braucht folgendes
1. FRM (Flyff Resource Manager)
2. Integrity Bypasser
Und so geht es:
Als erstes öffnet ihr mit dem FRM die data.res...
200 Attribut Punkte am Anfang 09/16/2006 - Guild Wars - 14 Replies Als ich den char gemacht hab, hatte ich im tutorial schon 200 attributpunkte :) (factions)
http://www.zerowaitingtime.com/4043-download-gw00 1.bmp
Attribut Hack 01/08/2006 - Guild Wars - 7 Replies Gibt es einen Hack, der die Anzahl der Atrriputpunkte erhöht? Hab mal nen Screen gesehen, wo jemand bei jedem Atrribut über 200 Punkte hatte :eek:
Bitte um Link oder sonstiges
mfg