Read XML Document Using VBScript and HTML5

This article explains how to import and read XML documents using VBScript and HTML 5.

XML reader Home page
Figure 1: XML reader home page

Step 1

  1. Open Notepad.

  2. Add the following XML code.
    1. <SERVER>  
    2.    <INTERFACE>  
    3.       <PORT>1</PORT>  
    4.       <IPADDRESS>10.100.4.9</IPADDRESS>  
    5.       <NETMASK>255.255.224.0</NETMASK>  
    6.    </INTERFACE>  
    7.    <INTERFACE>  
    8.       <PORT>2</PORT>  
    9.       <IPADDRESS>10.100.4.10</IPADDRESS>  
    10.       <NETMASK>255.255.224.0</NETMASK>  
    11.    </INTERFACE>  
    12. </SERVER>  
  3. Save the file with the extension “.xml”.

Step 2

  1. Open Notepad.

  2. Add the following HTML code:
    1. <! DOCTYPE html>  
    2. <html>  
    3.    <head>  
    4.       <title>Page Title</title>  
    5.       <style>  
    6.          h1  
    7.          {  
    8.             color: #05E395;  
    9.          }  
    10.          fieldset {  
    11.             font-family: sans-serif;  
    12.             border: 5px solid #05E395;  
    13.             background: #ddd;  
    14.             border-radius: 5px;  
    15.             padding: 15px;  
    16.          }  
    17.          fieldset legend {  
    18.             background: #0BDB9D;  
    19.   
    20.             color: #fff;  
    21.             padding: 5px 10px ;  
    22.             font-size: 32px;  
    23.             border-radius: 5px;  
    24.             box-shadow: 0 0 0 5px #ddd;  
    25.             margin-left: 20px;  
    26.          }  
    27.       </style>  
    28.       <script language="vbscript" type="text/vbscript">  
    29.          Sub Handlechange()  
    30.              MsgBox "File Imported Sucessfully”, vbInformation  
    31.          End Sub  
    32.          Sub ExportXML  
    33.              Dim ObjXML  
    34.              Dim fileinput  
    35.              Dim Root  
    36.              Dim NodeList  
    37.              Dim Msg  
    38.              Dim port  
    39.              Dim ip  
    40.              Dim nextmask  
    41.              Set ObjXML = CreateObject ("Microsoft.XMLDOM")   
    42.              ObjXML.async = False   
    43.              fileinput = Document.getElementById ("browse").Value  
    44.              ObjXML.load(fileinput)  
    45.              Set Root = ObjXML.documentElement   
    46.              Set NodeList = Root.getElementsByTagName("INTERFACE")   
    47.              For Each Elem In NodeList   
    48.                  Set port = Elem.getElementsByTagName ("PORT") (0)  
    49.                  Set ip = Elem.getElementsByTagName ("IPADDRESS") (0)  
    50.                  Set netmask= Elem.getElementsByTagName ("NETMASK") (0)  
    51.                  Msg ="[PORT :]" & port.Text & vbNewLine  
    52.                  Msg = Msg & "[IP ADDRESS :]" & ip.Text & vbNewLine  
    53.                  Msg = Msg & "[NETMASK :]" & netmask.Text  
    54.                  MsgBox Msg  
    55.              Next  
    56.              MsgBox "Data Read Sucessfully”, vbInformation  
    57.          End Sub  
    58.       </script>  
    59.    </head>  
    60. <body>  
    61.    <form>  
    62.       <section style="margin: 10px ;">  
    63.       <fieldset style="min-height:100px;">  
    64.          <legend><b>CsharpCorner </b> </legend>  
    65.          <center>  
    66.             <h1>XML Reader</h1>  
    67.   
    68.             <img src="C:\Users\Karthikeyan.K\Desktop\File_type_Extension_22-256.png" alt="View" style="width:218px;height:256px;">  
    69.             <br>  
    70.             <br>   
    71.             <input type="file" id="browse" name="fileupload" onChange="Handlechange()"/>  
    72.             <br>  
    73.             <br>   
    74.             <input type="button" value="Export" id="Export" onclick="ExportXML()"/>  
    75.          </center>  
    76.          <label> <br/> </label>  
    77.          <label> <br/> </label>   
    78.       </fieldset>  
    79.    </form>  
    80. </body>  
    81. </html>  
  3. Save the file with extension the “.html”.

Output

  1. Open the HTML document.

  2. Click the browse button.

    Browse the XML document
    Figure 2: Browse the XML document

  3. Choose the XML document.

    Select the XML document
    Figure 3: Select the XML document

    File Imported Successfully
    Figure 4: File Imported Successfully

  4. Press the Export button.

    XML document Export
    Figure 5: XML document Export

    XML data Output 1
    Figure 6: XML data Output 1

    XML data Output 2
    Figure 7: XML data Output 2

    Data Read Successfully
    Figure 8: Data Read Successfully

Conclusion

Thanks for reading. I hope you liked this article. Please provide your valuable suggestions.

Up Next
    Ebook Download
    View all
    Learn
    View all