[Original] My own XML processing class! There is more functions but have limitations!

xiaoxiao2021-03-06  38

Package jdom; / *

News Dedicated XML File Function: Delete Added by Up to Under The Lower Add Read By Under Direction, you can limit the recording by deleting X strips from top to bottom, how much is recorded, more time to delete old Inserting new data full data exchange using arraylist to handle discomfort: scalability is not strong for specific XML files, no unlimited levels of access child nodes, performance has not been optimized!

* /

Import java.ior. *; import java.lang. *; import org.jdom. *; import org.jdom.output. *; import org.jdom.input. *; import javax.servlet .http.httpservletRequest; import javax.servlet.jsp.pageContext; import com.ntsky.file.fileutil; // A class uploaded class ~ I call to generate a directory, please contact me if you need it ..

Public class writeXml {// Initializing object variable private string root_jsp = new string (); // directory root path private string filename = new string (); // XML file name private string secon_root = new string (); // creation directory Private arraylist postlist = null; // store data record private map map = new hashmap (); private int maxline = 0; // xml node's maximum number of private int Docus = 0; // Store XML number private document read_doc = New document (); private document public_doc = new document (); private string root_temp_file = ""; private string first_dir = "

Public void buildxml () throws exception // New an XML file

{Element root, news_rom, id, title, file_route, postday; root = new element ("news_info"); // Generate root element: student-info read_doc = new document (root); this.docline = 0; build );

} PUBLIC VOID ADDXML () THROWS Exception / / Add a node to XML

{Element root; // Generate root elements: info root = read_doc.getrootElement (); // Get root element // put root elements into the document DOC build (root);

}

Public void build (element root) THROWS Exception // Write data to XML file {Element news_rom, id, title, file_route, postday, sate; if (docline> maxline) {if (! DELXML (DOCLINE - MAXLINE)) {/ / Clean out space return; // If clean up the error exit program} else {this.docline = maxline;}} int a = postlist.size () / 5; // To store the number INT b = maxline - docline; // Air position if (a> = maxline) // If you need to add more records than maximum numbers a = maxline; // stored to maximum number IF (a <0) a = postlist.size () / 5; if A - b> = 0) {// The required space required to store records

IF (! DELXML (A-B)) // Clean out space return; // If clean up error exit program}

// for (int i = 0; i <(a * 5); i = i 5) for (int i = (A * 5) -1; I> = 0; i = i - 5) {news_rom = NEW ELEMENT ("news_rom"); // Generate Elements: This element will contain elements Number, Name, Age ID = New Element ("ID"); title = new element ("title"); file_route = new element (" File_route "); postday = new element; SATE = New Element (" SATE "); id.settext ((string) PostList.get (I-4)); title.settext (String) PostList. GET (I-3)); file_route.settext (String) PostList.get (I-2)); postday.settext (String) PostList.get (I-1)); Sate.Settext (String) PostList .get (i));

News_rom.addcontent (ID); news_rom.addcontent (title); news_rom.addcontent (file_route); news_rom.addcontent (postDay); news_rom.addcontent (SATE); root.addcontent (news_rom);}

THIS.PUBLIC_DOC = Read_Doc;

Public int GET_DOCLINE () {

Return this.docline;

}

Public int GET_MAXLINE () {

Return this.maxline;

}

Public void readxml_defail (String province) THROWS Exception // Node Record of the recorded ID

{Element myelement = read_doc.getrootElement (); // Get root node list Listtwo = myelement.getChildren (); // Get list, ready to traverse all nodes map a = new hashMap (); for (int i = 0; i < Listtwo.size (); i ) {ELEMENT E_KEY = (Element) Listtwo.get (i); // Get element IF under node (province.equals ("province"). getTextTrim ())) / / Compare the ID value is equal {ELEMENT E_KEY_CHILD = E_KEY.GETCHILD ("URL_XML"); for (int J = 1; j <= 9; j ) A.PUT ("new _" j, e_key_child.getchildtext ("url_xml_" J)); Break;}} this.map = a;} public arraylist readxml_one (string id) THROWS exception // Node recorded node record {ELEMENT MyElement = read_doc.getrootelement (); // Get root node List ListTWO = MyElement.getChildren (); // Get list, ready to traverse all nodes arraylist a = new arraylist (); for (int i = 0; i

{Element myelement = read_doc.getrootElement (); // Get root nodes list Listttwo = myelement.getchildren (); // Get list, ready to traverse all nodes arraylist a = new arraylist (); int temp = 0; if (Listtwo .Size ()> = Number) Temp = Listtwo.size () - Number; else temp = 0; for (int i = Listtwo.size () - 1; i> = 0 && I> = Temp; I -) {ELEMENT E_KEY = (ELEMENT) Listtwo.get (i); // Get element a.add (e_key.getchild ("ID") under the node. GetTextTrim ()); a.add (e_key.getchild ("Title" ). Gettexttrim ()); A.Add (e_key.getchild ("file_route"). getTextTrim ()); A.Add (e_key.getchild ("postday"). getTextTrim ()); a.add (e_key.getchild ("SATE"). GetTextTrim ());

} RETURN A;} public arraylist readxml_all_id (int Number) THROWS Exception // All records read

{Element myelement = read_doc.getrootElement (); // Get root nodes list Listttwo = myelement.getchildren (); // Get list, ready to traverse all nodes arraylist a = new arraylist (); int temp = 0; if (Listtwo .Size ()> = Number) Temp = Listtwo.size () - Number; else temp = 0; for (int i = Listtwo.size () - 1; i> = 0 && I> = Temp; I -) {ELEMENT E_KEY = (Element) Listtwo.get (i); // Get the element under the node

a.add (e_key.getchild ("id"). GetTextTrim ());

} RETURN A;

Public void editXML (String id) throws exception // modified record is the node of the ID

{ELEMENT myelement = read_doc.getrootElement (); // Get root nodes list Listtwo = myelement.getchildren (); // Get list, ready to traverse all nodes for (int i = 0; i

MyElement.getChildren (); // Get list, ready to traverse all node for (int i = 0; i

Public void WreitXML_File () throws exception // Generate files to hard drive

{

Format Format = Format.getCompactFormat ();

Format.setencoding ("GB2312"); // Set the character of the XML file to GB2312

Format.SetinDent ("); // Sets the indentation of the XML file to 4 space XMloutputter XMlout = new xmloutputter (format); // After the elements, the elements are replaced by each layer.

XMlout.Output (public_doc, new fileoutputstream (get_fullrootfile ()));

}

// Take data from the hard disk to memory

public boolean readXML () throws Exception {try {SAXBuilder builder = new SAXBuilder (); this.read_doc = builder.build (Get_FullRootFile ()); Element MyElement = read_doc.getRootElement (); // get the root List listTwo = MyElement. GetChildren (); this.docline = Listtwo.size (); listtwo = null; return true;} catch (exception e) {E.PrintStackTrace (); return false;}}

Public void set_postlist (arraylist postlist) {// XML Add recorded data source

THIS.POSTLIST = PostList;

} Public void initialize (String URL)

{// Take the root directory path of the servlet

THIS.ROOT_JSP = URL;}

Public void Initialize (PageContext PageContext)

{// take the JSP root directory path

THIS.ROOT_JSP = PageContext (). getRealPath ("/");} public void set_maxlint (int MAX)

{// Maximum license memory this.maxline = max;}

Public void setXMLFileName (String filename)

{// Setting the XML file name string temp = new string (); if (filename.tolowercase (). Endswith (". Xml")) {this.filename = filename;} else {temp = filename ".xml"; This.FileName = Temp;}} public void firstdir (String Rot) {// Set the first directory IF (Rot.endSwith ("/")) this.first_dir = rot; else this.first_dir = rot "/";} Public void creatdir () {try {

FileUtil C = new fileutil (); string fem_d = get_secon_root ();

C. MakeDir (Fild_D, root_jsp);

} catch (exception e) {

}

Public void setsecon_root (String Secon_Root)

{// Setting the directory IF (Secon_Root.endSwith ("/")) this.secon_root = first_dir second_root; else this.secon_root = first_dir second_root "/";

}

Public void setfull_r_name (string roco) {

// Enter data by the superior program this.Root_Temp_File = ROO;

}

// Return to data

Public String get_initialize ()

{// return root path

Return this.root_jsp;

}

Public string get_setXMLFileName ()

{// Return to XML file name

Return this.filename;

}

Public string get_secon_root ()

{// Return to the creation

Return this.secon_root;

}

Public String get_fullrootfile ()

{// Return detailed file name path if (this.root_temp_file.equals (")) Return get_initialize () get_secon_root () get_setXMLFileName (); else return get_initialize () this.Root_Temp_File;

}

Public string get_dir_file () {

/ / Return detailed file name path if (this.root_temp_file.equals (")) Return GET_SECON_ROOT () GET_SETXMLFILENAME (); else return this.root_temp_file;

} Public map getInputMap () {return this.map;} public string getString (String key) {// TODO automatic generation method stub Return (String) map.get (key);}} is used to manage two XML files first (This XML stores the second XML path): defail xml / x02.xml xml / x02.xml nofile nofile xml / x05.xml Nofile XML / X07.XML XML / X08.XML NOFILE 1 nofile xml / 1 / x02.xml nofile nofile xml / 1 / x05.xml nofile nofile nofile nofile Second (store some news basic information): 22 title </ title> <file_route> file.htm </ file_route> <postday> 2005-01 -25 23: 51: 52.0 </ postday> <Sate> 3 </ SATE> </ news_rom> </ news_info></p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-60585.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="60585" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.034</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'TVvAoXV9O1bFnHl4TTIsqQlHiYyoCn6NI_2F6rl7sbrP_2F2hMux_2BtU49zTB2HbS9n_2FUAvI72QDd0htIAaCyUFwz_2Fg_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>