<html>
    <head>
    <title name="title">
        Weather Service WSDL Form
      </title>
    <script language="JavaScript">
    function ProcessWSDLDocument()
    {
        var para = document.createElement("p");
        para.align="center";
        document.body.appendChild(para);
        var xmlDoc = new ActiveXObject("MSXML2.DOMDocument.4.0");
        xmlDoc.async = false;
        xmlDoc.load("Listing1.wsdl");

        if (xmlDoc.parseError.errorCode != 0)
            alert("WSDL File parsing error occurred.");
        else 
        {
            definitionsElement = xmlDoc.documentElement;
            var definitionsNamespacePrefix = getPrefix(definitionsElement.nodeName);
            var definitionsNamespaceURI = 
                getNamespaceURI(definitionsElement, definitionsNamespacePrefix);

            if ((definitionsNamespaceURI!="http://schemas.xmlsoap.org/wsdl/") ||
                (getLocalName(definitionsElement.nodeName)!="definitions"))
                alert ("Invalid WSDL.. 
                   [either namespace or <definitions> element is incorrect]");
            else 
            {
                var serviceElement = null;
                definitionChildren = definitionsElement.childNodes;
                for (i=0; i<definitionChildren.length; i++)
                {
                   if ((getLocalName(definitionChildren.item(i).nodeName)=="service") &&
                       (definitionChildren.item(i).nodeType==1))
                        para.appendChild(getServiceTable(definitionChildren.item(i)));
                }//for

            }// else if (getSuffix)
        }// esle if (xmlDoc.parseError.errorCode != 0)
    }// ProcessWSDLDocument()


    function getServiceTable(serviceElement)
    {
        var table = document.createElement("table");
        table.border="6";
        table.bgColor="#F0F8FF";
        table.cellPadding="4";
        table.cellSpacing="5";
        table.borderColor="#D2B48C";

        var tBody = document.createElement("tbody");
        table.appendChild(tBody);

        tBody.appendChild(createRow("Name of Service", serviceElement.getAttribute("name")));

        var serviceChildren = serviceElement.childNodes;
        var documentationElement = null;

        for (i=0; i<serviceChildren.length; i++)
            if ((getLocalName(serviceChildren.item(i).nodeName)=="documentation") &&
                (serviceChildren.item(i).nodeType==1)) {
                documentationElement = serviceChildren.item(i);
                var documentation = documentationElement.firstChild.nodeValue;
                tBody.appendChild(createRow ("Service Description", documentation));
                break;
            }//if

        // Now read the port element:
        var portElement = getChild(serviceElement, "port");

        if (portElement == null)
            alert ("No <port> element found!!");
        else
        {
            var portName = portElement.getAttribute("name");
            var serviceSiblings = serviceElement.parentNode.childNodes;

            for (var i=0; i<serviceSiblings.length; i++)
            {
               if ((getLocalName(serviceSiblings.item(i).tagName)=="portType") &&
                   (serviceSiblings.item(i).getAttribute("name")==portName))
               {
                   var portTypeElement = serviceSiblings.item(i);
                   attachPortTypeSetOfRows(tBody, portTypeElement);
               }//if
            }//for
        }//else

     return table;
    }//getServiceTable


    function attachPortTypeSetOfRows (tBody, portTypeElement)
    {
        var OperationsList = portTypeElement.childNodes;
        for (var i=0; i<OperationsList.length; i++)
        {
            if (getLocalName(OperationsList.item(i).tagName)=="operation")
                attachOperationSetOfRows(tBody, OperationsList.item(i));
        }//for    
    }//getPortTypeSetOfRows 


    function attachOperationSetOfRows(tBody, OperationElement)
    {
        tBody.appendChild(
            createRow("Name of Operation",OperationElement.getAttribute("name")));
        var documentationElement = getChild(OperationElement, "documentation");
 
        if (documentationElement != null)
            tBody.appendChild(
             createRow ("Description of Operation",documentationElement.firstChild.nodeValue));

        var inputElement = getChild(OperationElement, "input");
        var messageElement = null;

        if (inputElement!=null) {
            var inputMessage = inputElement.getAttribute("message");
            var operationParentSiblings = OperationElement.parentNode.parentNode.childNodes;

            for (var i=0; i<operationParentSiblings.length; i++)
            {
                if ((getLocalName(operationParentSiblings.item(i).tagName)=="message") && 
                    (operationParentSiblings.item(i).getAttribute("name")==inputMessage)) {
                    attachMessageRows(tBody, operationParentSiblings.item(i));
                    break;
                }//if
            }//for
        }//if
 
    }//attachOperationSetOfRows


    function attachMessageRows(tBody, messageElement)
    {
        var form = document.createElement("form");
        form.action = "http://localhost/DOM4WS/SoapRequestGenerator";
        form.method = "GET";

        var partElements = messageElement.childNodes;
        for (var i=0; i<partElements.length; i++) 
        {
            if (getLocalName(partElements.item(i).tagName) == "part")
                attachPartRow(form, partElements.item(i));
        }//for

        var input = document.createElement("input");
        var emptycell = document.createElement("td");
        var cell = document.createElement("td");
        input.size="25";
        input.name="Submit";
        input.type="submit";
        input.value="Submit Query";
        cell.appendChild(input);

        var row = document.createElement("tr");
        row.bgColor = "#D2B48C";
        row.appendChild(emptycell);
        row.appendChild(cell);
        form.appendChild(row);
        tBody.appendChild(form);

    }//attachMessageRows


    function attachPartRow(form, partElement)
    {
        var row = document.createElement("tr");
        row.bgColor = "#D2B48C";

        var cell = document.createElement("td");
        var bold = document.createElement("b");
        bold.appendChild(document.createTextNode("Enter "+partElement.getAttribute("name")));
        cell.appendChild(bold);
        row.appendChild(cell);

        cell = document.createElement("td");
        var input = document.createElement("input");
        input.size="25";
        input.name=partElement.getAttribute("name");
        input.type="text";
        cell.appendChild(input);
        row.appendChild(cell);

        form.appendChild(row);

    }//attachPartRow


    function createRow( label, text ) 
    {
        var row = document.createElement("tr");
        row.bgColor = "#FDF5E6";

        var cell = document.createElement("td");
        var bold = document.createElement("b");
        var labelTextNode = document.createTextNode(label);
        bold.appendChild(labelTextNode);
        cell.appendChild(bold);
        row.appendChild(cell);

        cell = document.createElement("td");
        cell.appendChild(document.createTextNode(text));
        row.appendChild(cell);
        return row;
    }//createRow


    function getChild(parentElement, childName)
    {
        var childElement = null;
        var children = parentElement.childNodes;

        for (var i=0; i<children.length; i++)
        {
            if (getLocalName(children.item(i).tagName)==childName) {
                childElement = children.item(i);
                break;
            }//if
        }//for

       return childElement;

    }//getChild


    function getNamespaceURI(elementNode, namespacePrefix)
    {
        var namespaceURI = null;
        if (elementNode.nodeType == 9)
            return null;
        else 
        {
            namespaceURI = findNamespace (elementNode, namespacePrefix);
            if (namespaceURI == null)
                namespaceURI = getNamespaceURI(elementNode.parentNode, namespacePrefix);
            else
                return namespaceURI; 
        }//else

        return namespaceURI;

    }//function getNamespaceURI()


    function findNamespace(elementNode, namespacePrefix)
    {
        var attributes = elementNode.attributes;
 
        if ((attributes!=null) && (attributes.length > 0))
        {
            for (var x=0; x<attributes.length; x++)
            {
                var attributeNamespacePrefix = getPrefix(attributes.item(x).nodeName);
                var attributeNamespaceSuffix = getLocalName(attributes.item(x).nodeName);

                if (( attributeNamespacePrefix == null) && 
                    (attributeNamespaceSuffix == "xmlns"))
                    return attributes.item(x).nodeValue;

                else if ((attributeNamespacePrefix == "xmlns") && 
                         (attributeNamespaceSuffix == namespacePrefix))
                    return attributes.item(x).nodeValue;

            }// for (var x=0; x < attributes.length; x++)

            return null;
        }// if (attribute!=null)

    }//function addNamespace (elementNode)


    function getPrefix(tagName)
    {
        var prefix;
        var prefixIndex = tagName.indexOf(":");

        if (prefixIndex == -1)
            return null;
        else 
            return prefix = tagName.substring(0, prefixIndex);

    }//function getPrefix()


    function getLocalName(tagName)
    {
        var suffix;
        var prefixIndex = tagName.indexOf(":");

        if (prefixIndex == -1)
            return tagName;
        else 
            return suffix = tagName.substring (prefixIndex+1, tagName.length);

    }//function getLocalName()


    </script>
    </head>

    <body onload="ProcessWSDLDocument()">
    </body>      
</html>