Provided by Water Cleaners: javascript is used to extract data from any XML file into hierarchical display.
Http://topic.csdn.net/u/20080921/15/655b8f3c-3fbe-42aa-a53a-630bfdb1ae9b.html
Other people's things are not perfect, but they should be added to the favorites.
- <HTML>
- <Body> </body>
- <SCRIPT>
- Function xml2html (file)
- {
- VaR xmldoc = new activexobject ("Microsoft. xmldom ");
- Xmldoc. Load (File );
- VaR result = "<ul>" + node2html(xmldoc.doc umentelement) + "</ul> ";
- Return result;
- }
- Function node2html (node)
- {
- VaR result = "<li> ";
- If (node. nodetype = 3)
- Return ""; // if it is text
- Else result + = node. nodename;
- If (node. childnodes. length> 0)
- {
- Result + = "<ul> ";
- For (VAR I = 0; I <node. childnodes. length; I ++)
- Result + = node2html (node. childnodes [I]);
- Result + = "</ul> ";
- }
- Result + = "</LI> ";
- Return result;
- }
- Document. Body. innerhtml = xml2html ("A. xml ");
- </SCRIPT>
- </Html>
Zjm1126qqcomCode:
- You only need to put XML and this file in the same directory (the name should be the same, for example, A. XML)
- HTML code <HTML>
- <SCRIPT>
- VaR A = new activexobject ("Microsoft. xmldom ");
- A. Load ("A. xml ");
- VaR B = A. xml;
- VaR c =/<[^?] /S *?> | <[^?] *? /S/B/g;
- VaR d = B. Match (c). tostring ();
- VaR E =/<|> | []/g;
- VaR F = D. Replace (E ,"");
- VaR G = f. Split (",");
- VaR STR;
- Document. Write (g );
- Function BB (B ){
- VaR r = B. length;
- VaR x = [];
- For (VAR I = 0; I <r; I ++ ){
- For (var j = I; j <r; j ++ ){
- If (B [J] = "/" + B [I]) {
- If (J-I> 1 ){
- B [I] = "<li>" + B [I];
- X [I] = B [I] + "<ul> ";
- X [J] = "</ul> </LI> ";
- }
- Else {
- B [I] = "<li>" + B [I] + "</LI> ";
- }
- B [J] = "";
- Break;
- }
- }
- }
- For (VAR I = 0; I <X. length; I ++ ){
- If (X [I]! = NULL)
- B [I] = x [I];
- }
- B. splice (0, 0, "<ul> ");
- B. splice (B. length, 0, "</ul> ");
- Return B. Join ("");
- }
- Document. Body. innerhtml = BB (g );
- </SCRIPT>
- </Html>