Provided by Water Cleaners: javascript is used to extract data from any XML file into hierarchical display.

Source: Internet
Author: User

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.

 

  1. <HTML>
  2. <Body> </body>
  3. <SCRIPT>
  4. Function xml2html (file)
  5. {
  6. VaR xmldoc = new activexobject ("Microsoft. xmldom ");
  7. Xmldoc. Load (File );
  8. VaR result = "<ul>" + node2html(xmldoc.doc umentelement) + "</ul> ";
  9. Return result;
  10. }
  11. Function node2html (node)
  12. {
  13. VaR result = "<li> ";
  14. If (node. nodetype = 3)
  15. Return ""; // if it is text
  16. Else result + = node. nodename;
  17. If (node. childnodes. length> 0)
  18. {
  19. Result + = "<ul> ";
  20. For (VAR I = 0; I <node. childnodes. length; I ++)
  21. Result + = node2html (node. childnodes [I]);
  22. Result + = "</ul> ";
  23. }
  24. Result + = "</LI> ";
  25. Return result;
  26. }
  27. Document. Body. innerhtml = xml2html ("A. xml ");
  28. </SCRIPT>
  29. </Html>

 

Zjm1126qqcomCode:

 

 

  1. You only need to put XML and this file in the same directory (the name should be the same, for example, A. XML)
  2. HTML code <HTML>
  3. <SCRIPT>
  4. VaR A = new activexobject ("Microsoft. xmldom ");
  5. A. Load ("A. xml ");
  6. VaR B = A. xml;
  7. VaR c =/<[^?] /S *?> | <[^?] *? /S/B/g;
  8. VaR d = B. Match (c). tostring ();
  9. VaR E =/<|> | []/g;
  10. VaR F = D. Replace (E ,"");
  11. VaR G = f. Split (",");
  12. VaR STR;
  13. Document. Write (g );
  14. Function BB (B ){
  15. VaR r = B. length;
  16. VaR x = [];
  17. For (VAR I = 0; I <r; I ++ ){
  18. For (var j = I; j <r; j ++ ){
  19. If (B [J] = "/" + B [I]) {
  20. If (J-I> 1 ){
  21. B [I] = "<li>" + B [I];
  22. X [I] = B [I] + "<ul> ";
  23. X [J] = "</ul> </LI> ";
  24. }
  25. Else {
  26. B [I] = "<li>" + B [I] + "</LI> ";
  27. }
  28. B [J] = "";
  29. Break;
  30. }
  31. }
  32. }
  33. For (VAR I = 0; I <X. length; I ++ ){
  34. If (X [I]! = NULL)
  35. B [I] = x [I];
  36. }
  37. B. splice (0, 0, "<ul> ");
  38. B. splice (B. length, 0, "</ul> ");
  39. Return B. Join ("");
  40. }
  41. Document. Body. innerhtml = BB (g );
  42. </SCRIPT>
  43. </Html>

 

 

 

Related Article

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.