Because of the work required, the following XML needs to be generated:
<?XML version= "1.0" encoding= "UTF-8"?><Root><ScormTheme= "2016-06-22 18:09:45"Speakor=""Introduction=""Scromtype= "1"><videolistName= "Channel 1"Count= "1"><VideoFile= "111.mp4" Time= "118000"/></videolist><videolistName= "Channel 2"Count= "1"><VideoFile= "222.mp4" Time= "118000"/></videolist><indexlistCount= "0"/><ChangelistCount= "0"/></Scorm></Root>
View Code
Here's how to write:
Public voidcreatxml (String path, string[] names, string[] timelengths)throwsIOException {Path= path + "\\assets\\"; Document Doc=documenthelper.createdocument (); //Add root nodeElement root = doc.addelement ("root"); //Add child elementsElement scorm = root.addelement ("Scorm"); //to add a property to a child nodeScorm.addattribute ("Theme", "" "); Scorm.addattribute ("Speakor", "" "); Scorm.addattribute ("Introduction", "" "); Scorm.addattribute ("Scromtype", "1"); for(inti = 0; i < names.length; i++) {String name= Names[i].substring (names[i].lastindexof ("\ \") + 1, Names[i].length ()); Element videolist= Scorm.addelement ("Videolist"); Videolist.addattribute ("Name", "channel" + (i + 1)); Videolist.addattribute ("Count", "1"); Element Video= Videolist.addelement ("Video"); Video.addattribute ("File", name); Video.addattribute ("Time", Timelengths[i]); } Element indexlist= Scorm.addelement ("Indexlist"); Indexlist.addattribute ("Count", "0"); Element Changelist= Scorm.addelement ("Changelist"); Changelist.addattribute ("Count", "0"); //instantiating an output format objectOutputFormat format =Outputformat.createprettyprint (); //Set Output EncodingFormat.setencoding ("UTF-8"); //Create a file object to write toFile File =NewFile (path + file.separator + "Videolist.xml"); //generate XmlWriter objects, parameters in constructors are file streams and formats that require outputXMLWriter writer =NewXMLWriter (Newfileoutputstream (file), format); //start writing, the Write method contains the Document object created aboveWriter.write (DOC); }
View Code
Call:
1 string[] names = {"1 channel", "2 Channel", "3 Channel"}; 2 string[] timelengths = {"$", "$", "$"}; 3 String path = "e:\\video\\"; 4 5 creatxml (path,names,timelengths);
View Code
Java generates XML files