java dom4j parser - ændre xml - dokument

, demo eksempel, her er xml - er vi nødt til at ændre:,,, <?xml - version = "0"?> <class> <student rollno="393"> <firstname>dinkar</firstname> <lastname>kad</lastname> <nickname>dinkar</nickname> <marks>85</marks> </student> <student rollno="493"> <firstname>Vaneet</firstname> <lastname>Gupta</lastname> <nickname>vinni</nickname> <marks>95</marks> </student> <student rollno="593"> <firstname>jasvir</firstname> <lastname>singn</lastname> <nickname>jazz</nickname> <marks>90</marks> </student> </class> , ,,Demo Example:,,,DOM4jModifyXMLDemo.java, pakke com.tutorialspoint.xml; import java.io.file; import java.io.ioexception; import java.io.unsupportedencodingexception; import java.util.iterator; import java.util.list; import org.dom4j.document; import org.dom4j.documentexception; import org.dom4j.element; import org.dom4j.node; import org.dom4j.io.outputformat; import org.dom4j.io.saxreader; import org.dom4j.io.xmlwriter; offentlige klasse dom4jmodifyxmldemo {offentlige statisk tomrum vigtigste (string [] args) (prøve (sag inputfile = ny fil ("input. txt"); saxreader læser = nye saxreader(); dokument = læser. læs (inputfile); element classelement = dokument. getrootelement(); listen < node > knudepunkter = dokument. selectnodes ("/klasse /elev [@ rollno ='493 ']") til (node node: knudepunkt) {element element = (del) node; iterator < element > iterator = element. elementiterator ("mærker"), mens (iterator. hasnext()) {element markselement = (del) iterator. next(); markselement. settext ("80")) //- print det dokument, system.out outputformat format = outputformat. createprettyprint(); xmlwriter forfatter, forfatter = nye xmlwriter (system.out, format); forfatter. skrive (nummer)} fangst (documentexception e) (f. printstacktrace();} fangst (unsupportedencodingexception e) (e.printstacktrace();} fangst (ioexception e) (f. printstacktrace();}}}, vil det føre til følgende resultat:, <?xml - version = "0" kodning = "utf - 8"?> <class> <student rollno="393"> <firstname>dinkar</firstname> <lastname>kad</lastname> <nickname>dinkar</nickname> <marks>85</marks> </student> <student rollno="493"> <firstname>Vaneet</firstname> <lastname>Gupta</lastname> <nickname>vinni</nickname> <marks>80</marks> </student> <student rollno="593"> <firstname>jasvir</firstname> <lastname>singn</lastname> <nickname>jazz</nickname> <marks>90</marks> </student> </class> ,



Previous:
Next Page: