HTML tree structure, XML to TREE tree

Source: Internet
Author: User

Some of my solutions need to use the XML structure, for example, to generate the XML class without any need to read the database from time to time for foreground operations. I have previously written XML to tree, which is not conducive to search engine optimization. So I chose a scheme to convert XML into HTML and then make HTML into a tree.

First

The HTML structure is as follows:

<DL>
<DT> content </DT>
<DD>
Subclass, so repeated
</DD>
</Dl>

Firebug Diagram

JSCode:

Function html2tree (box, type) {This. panel = This. get (box); this. init (); If (type) {This. panel. classname = 'html2tree html2tree _ '+ type ;}}; html2tree. prototype = {init: function () {var nodes = This. tag ('dl ', this. panel), S = this; for (VAR I = nodes. length; I --;) {var DL = nodes [I], DD = This. tag ('dd', DL), dT = This. tag ('dt', DL) [0]; this. setlast (DL); If (DD. length = 0) {DT. classname = 'fi Le ';} else if (S. Display (Dd [0])! = 'None') {DT. classname = 'open';} This. live (function () {var dd = S. next (this), open; If (dd) {open = S. display (dd) = 'none' DD. style. display = open? 'Block': 'none'; this. classname = open? 'Open': ''; }}, function () {return/DT/I. test (this. nodename) ;}) ;}, display: function (EL) {var cc = el. currentstyle | document. defaultview. getcomputedstyle (El, null); Return el. style ['display'] | CC ['display'];}, live: function (FN, c) {This. panel. onclick = function (e) {e = E | window. event; var S = E. srcelement | e.tar get; while (S & S! = This) {If (C. call (s) {fn. call (S, e); break;} s = S. parentnode ;}}, next: function (DT) {var next = DT, DD; do {next = next. nextsibling; If (next &/DD/I. test (next. nodename) {dd = next; break;} while (next); Return dd;}, setlast: function (DL) {var last = DL, next = dl; do {next = next. nextsibling; If (next &/dl/I. test (next. nodename) {last = next;} while (next); last. class Name = 'last';}, get: function (EL) {return typeof El = "string "? Document. getelementbyid (EL): El ;}, Tag: function (TAG, El) {return (El | document. Body). getelementsbytagname (TAG );}};

Call Method

 
New html2tree ('tree ', 'Min'); // skin: Red, XP, Min, circle, A3, black, CHM // The second parameter is skin, 7 skin types supported

Finally, we will package and download the code. Haha, you are welcome to make a brick. Please do not speak the same language. You can choose to use it or not .!

Thank you!

Original Code. For reprint, please contact Chai Ge !!!

Click to download

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.