Xml Realtime Examples 2t1b6x

  • November 2021
  • PDF

This document was ed by and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this report form. Report 3b7i


Overview 3e4r5l

& View Xml Realtime Examples as PDF for free.

More details w3441

  • Words: 13,471
  • Pages: 67


UGP 4.

6_UGP_4.xml William Anderson
13, Cross Street
New York <STATE>New York USA 6785764
Bill Sanders
13, Crick Street
Seattle <STATE>Washington

©NIIT

eXtensible Markup Language 39

USA 608475
6_UGP_4.xsl <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/"> <xsl:for-each select="CUSTDETAILS/CUSTOMER">
  • <xsl:value-of select="@CUSTID"/>
  • <xsl:value-of select="CUSTNAME"/>
  • <xsl:value-of select="ADDRESS"/>
  • <xsl:value-of select="CITY"/>
  • <xsl:value-of select="STATE"/>
  • <xsl:value-of select="COUNTRY"/>
  • <xsl:value-of select="PHONE"/>




  • Lesson Seven Experiences Introduce the functions of a parser in of its disadvantages, as the parser alone will not allow you to traverse from one portion of the XML document to the other. Then, introduce the Document Object Model (DOM) as a solution for the same. Refer to the latest at www.W3C.org on development of DOM for XML. Instruct the students that the “I” in the IXMLDOMNode, IXMLDOMNodeList, and IXMLDOMParseError objects stands for interface. These are the basic interfaces, which are implemented by various objects of XML DOM.

    Solutions: Just a Minute… 1.

    The details about products sold at CyberShoppe are stored in an XML document called product.xml. Write the code to display the price of all products by using DOM objects.

    7_JAM_1.htm <script language="JavaScript"> function loadXML() { var myxmlDoc = new ActiveXObject("Msxml2.DOMDocument.4.0") myxmlDoc.async=false myxmlDoc.load("products.xml") var myelement = myxmlDoc.getElementsByTagName("PRICE"); for (i=0; i<= myelement.length -1; ++i) {

    40 eXtensible Markup Language

    ©NIIT

    alert(myelement.item(i).text) } } products.xml Barbie Doll This is a doll for children aged 11 and above 10 12 Mini Bus This is a toy for children aged 11 and above 20 12

    To execute the script, open the 7_JAM_1.htm page in the browser. As soon as the page is loaded in the browser, it will display message boxes displaying the prices of products. Notice that the getElementsByTagName function is used here to retrieve values of all elements named PRICE. Then, you can display these values by using the for loop to traverse through the node list returned by the getElementsByTagName() function.

    Lesson Eight Experiences You can begin the session by giving a brief recap about the various DOM objects discussed in the previous lesson. Ensure that the student understands the main methods and properties that are associated with each of the four objects. You can then explain the scenario that is specified for this lesson. This can be followed by an explanation of the objects that are required to process an XML documents using a style sheet document. First, create the XML and XSD documents. Next, you can talk about the code that is required to process the XML and XSD documents. You can also create the HTML documents that are required to display information to the end . Finally, explain the JavaScript code that must be used to link the various HTML and XML documents.

    ©NIIT

    eXtensible Markup Language 41

    Examples and Analogies You can compare the working of DOM with that of a linked list. First, explain the different parts of a linked list and the mechanism used to traverse a linked list. You can then compare this process with the way in which the DOM node tree is traversed.

    Additional Inputs One of the methods of applying an XSLT style sheet to an XML document is by using the XSLProcessor and XSLTemplate objects. These objects provide the advantages of working on a cached version of style sheets and for asynchronous mode of loading XML document. Another simple way of applying an XSLT style sheet to the XML document is by using the transformNode() method of the DOMDocument object, as shown in the following example: <SCRIPT LANGUAGE="JavaScript"> function LOADXML() { var xmldoc=new ActiveXObject("Msxml2.DOMDocument.4.0"); xmldoc.async=false; xmldoc.load("product.xml"); var xsldoc=new ActiveXObject("Msxml2.DOMDocument.4.0"); xsldoc.async=false; xsldoc.load("productlist.xsl"); x.innerHTML = xmldoc.transformNode(xsldoc); }
    The above code creates two instances of the DOMDocument object, one for loading the XML document and the other for loading the XSLT style sheet. Then, it calls the transformNode() method of the

    42 eXtensible Markup Language

    ©NIIT

    DOMDocument object that contains the XML document and es as an argument a reference of the other DOMDocument that contains the XSLT style sheet. The transformNode() method transforms the XML document into the specified format by applying the style sheet, which is displayed in the browser window. This is another simpler method of dynamically applying an XSLT style sheet to an XML document. However, the transformNode() method is a Microsoft extension to the W3C DOM.

    FAQ 1.

    What does Msxml2.FreeThreadedDOMDocument stand for? Msxml2.FreeThreadedDOMDocument is used to create a free threaded object. There are two kinds of threading models, rental and free-threaded. The rental model enables for single threaded access in which all objects are executed on a single thread. The free-threaded model enables multithreaded access. In this model, an object can be executed on any thread at any time.

    2.

    What is cache memory? Cache is a section of the memory of the computer that is made up of high speed Static Random Access Memory (SRAM) Information stored in the cache can be accessed faster than other portions of the RAM.

    3.

    Is there a method by which I transform a single node? Yes , there is. You can use the transformNode() method of the XMLDOMNode object to transform the information contained in a node and all its child nodes.

    Solutions: Just a Minute… 1.

    Write the code to add an XML schema called “products.xsd” to a schema collection.

    Solution: var xsdschemacache = new ActiveXObject("Msxml2.XMLSchemaCache.4.0"); var xmlDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.4.0"); xmlDoc.validateOnParse=true xmlDoc.load("products.xml"); var namespace=xmlDoc.namespaceURI; xsdschemacache.add(namespace,"products.xsd"); 2.

    The following JavaScript code is used create XSLTemplate and DOMDocument objects. Identify the errors in the code, if any. custss = new activexObject(MSXML.XSLTemplate.4) custdomdoc = activexobject( "MSXML.ThreadedDOMdocument.4.0);

    Solution: custss= new ActiveXObject("MSXML2.XSLTemplate.4.0"); custdomdoc = new ActiveXObject("MSXML2.FreeThreadedDOMDocument.4.0");

    ©NIIT

    eXtensible Markup Language 43

    3. Identify the errors in the following JavaScript code: xslProcObject.output=xmlDocObject; xslProcObject.Transform alert("xslProcObject"); Solution: xslProcObject.input=xmlDocObject; xslProcObject.transform(); alert(xslProcObject.output);

    Solutions: Guided Practice 8.P.1 The XML document containing the book details is given below: 8_P_1.xml <TITLE> MORNING, NOON, AND NIGHT SYDNEY SHELDON 10 100 <TITLE> THE CLIENT JOHN GRISHAM 20 250 <TITLE> A STRANGER IN THE MIRROR SYDNEY SHELDON 15 120 To display the above data in a tabular format, you can use the following style sheet: 8_P_1_a.xsl <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/">





    <xsl:for-each select="BOOKDETAILS/BOOK"> 44 eXtensible Markup Language ©NIIT
    TITLE AUTHOR PRICE QUANTITY
    <xsl:value-of select="TITLE"/> <xsl:value-of select="AFNAME"/> <xsl:text> <xsl:value-of select="ALNAME"/> <xsl:value-of select="PRICE" /> <xsl:value-of select="QUANTITY" />
    In the above code, the xsl:text element is used to add a space between the first name and last name of an author. To display the same book details in a list, you can use the following style sheet: 8_P_1_b.xsl <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/"> <xsl:for-each select="BOOKDETAILS/BOOK">
  • TITLE: <xsl:value-of select="TITLE"/>
    AUTHOR: <xsl:value-of select="AFNAME"/> <xsl:text> <xsl:value-of select="ALNAME"/>
    PRICE: <xsl:value-of select="PRICE" />
    QUANTITY: <xsl:value-of select="QUANTITY" />

  • To accept ’s choice of the view, you need to create a Web page containing frames. The left frame will display the controls for accepting input and the right frame will be used for results. For creating a blank page, you can use the following code: right.htm Untitled Document 6l4kr
    The div block in the above code will be used to display the list or table containing book details. You can use the following code for accepting ’s choice: left.htm Untitled Document 6l4kr <meta http-equiv="Content-Type" content="text/html; charset=iso8859-1"> <script language="javascript">

    ©NIIT

    eXtensible Markup Language 45

    var xmlDoc function loadXML() { xmlDoc = new ActiveXObject("Msxml2.DOMDocument.4.0"); xmlDoc.async = false; xmlDoc.load("8_P_1.xml"); } function ApplyXSL() { var xslt = new ActiveXObject("Msxml2.XSLTemplate.4.0"); var xslDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.4.0"); var xslProc; xslDoc.async = false; alert (stylesheet.value); xslDoc.load(stylesheet.value); xslt.stylesheet = xslDoc; xslProc = xslt.createProcessor(); xslProc.input = xmlDoc; xslProc.transform(); parent.right.x.innerHTML=xslProc.output; } <select name="stylesheet" onChange="ApplyXSL()"> The above code will display a drop-down list box for accepting ’s choice. As soon as the Web page is loaded, the loadXML function is invoked. This function loads the XML document in a DOMDocument object. When a selects one of the options given in the drop-down list box, the onchange event of the SELECT element is fired and the ApplyXSL function is called. This function simply applies appropriate style sheet to the XML document. Finally, you need to create the main page, which will be used to display left.htm and right.htm. <TITLE>XML/XSL Viewer Demo To execute the complete code, open index.htm in the browser and select one of the options from the drop-down list box.

    46 eXtensible Markup Language

    ©NIIT

    Solutions: Unguided Practice UGP 1. This file accepts the name of the XML file. It provides a text box and a submit hyperlink. On clicking the hyperlink, javascript code loads the XML document. If the XML file is well formed then the javascript function, extracts the elements whose node name is CUSTOMERNAME. The function then loops through the list of nodes returned by the output and if the text enclosed in the elements is "Harold Johnson", the function extracts the ADDRESS and the PHONENUMBER elements and sets the values accordingly and displays the output in a message box. XMLDisplayString.htm XML 1u3p2l <meta http-equiv="Content-Type" content="text/html; charset=iso8859-1">
    Enter the XML FileName Here
    Submit

     

    <script Language="javascript"> function cmdSubmit_click() { var objelements; if (frmXMLFileName.TxtName.value.length==0) { alert ("Invalid XML String"); } else { var xmldoc= new ActiveXObject("Msxml2.DOMDocument.4.0"); xmldoc.load(frmXMLFileName.TxtName.value); var error=xmldoc.parseError; if(error!="") { alert("Error");

    ©NIIT

    eXtensible Markup Language 47

    } else { objelements=xmldoc.getElementsByTagName("CUSTOMERNAME"); for(ctr=0;ctr<=objelements.length;ctr++) { if (objelements[ctr].text=="Harold Johnson") { objelements=xmldoc.getElementsByTagName("ADR ESS"); objelements[ctr].text="94, McFarlane Avenue"; objelements=xmldoc.getElementsByTagName("PHO NE"); objelements[ctr].text="412-233-2344";

    } }

    }

    alert(xmldoc.xml); break;

    } } Customer.xml Harold Johnson
    56, Regent Road
    London UK 444-425-2355


    UGP 2. This file accepts the name of the XML file. It provides a text box and a submit hyperlink. Clicking the hyperlinks uses dom and javascript to load the xml file. If the xml file is well formed then the JavaScript function, loops through the entire set of nodes present in the xml document using the childNode function and uses the nodeName, nodeType and nodeValue properties of DOMDocument class to display the output in a message box. XMLDisplayString.htm XML 1u3p2l <meta http-equiv="Content-Type" content="text/html; charset=iso8859-1">






    48 eXtensible Markup Language ©NIIT
    Enter the XML FileName Here
    Submit

     

    <script Language="javascript"> function cmdSubmit_click() { var objelements; if (frmXMLFileName.TxtName.value.length==0) { alert ("Invalid XML String"); } else { var xmldoc= new ActiveXObject("Msxml2.DOMDocument.4.0"); xmldoc.load(frmXMLFileName.TxtName.value); var error=xmldoc.parseError; if(error!="") { alert("Error"); } else { for(ctr=1;ctr<xmldoc.childNodes.length;ctr++) { alert("Node Name: " + xmldoc.childNodes[ctr].nodeName); alert("Node Type: " + xmldoc.childNodes[ctr].nodeTypeString); var objparentnode=xmldoc.childNodes[ctr]; for(ctr1=0;ctr1
    ©NIIT

    eXtensible Markup Language 49

    for(ctr2=0;ctr2
    }

    }

    } } movie.xml <MOVIE> <MOVIEID>M920 <MOVIENAME>The Last Emperor John Lone Bernado Bertolucci 1987 Drama

    UGP 3. The correct code for loading the emp.xml file and applying empss.xsl to it is as follows: <script language="javascript"> var empt = new ActiveXObject("Msxml2.XSLTemplate.4.0"); var emptdoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.4.0"); var empproc; emptdoc.async = false; emptdoc.load("empss.xsl"); empt.stylesheet = emptdoc; var empxml = new ActiveXObject("Msxml2.DOMDocument.4.0"); empxml.async = false; empxml.load("emp.xml"); empproc = empt.createProcessor(); empproc.input = empxml; empproc.transform(); alert(empproc.output);

    50 eXtensible Markup Language

    ©NIIT

    Solutions to Additional Exercises 1. This solution to the given problem can be achieved using three files, two .xsd files and a .xml file. The files required in the given scenario are as follows: a. commonschema.xsd - This xsd file holds the schema of all the reusable components in the solution. b. casehistory.xsd - This xsd file makes use of commonschema.xsd to define the schema for casehistory.xml c. casehistory.xml - This xml file has CASEHISTORY as the root element with an ID "C001". The information in this xml file is grouped into two elements, PERSONALINFORMATION and CASEINFORMATION. PERSONALINFORMATION stores the NAME,ADDRESS,GENDER,AGE, and EXISTINGDISEASES of a patient. The CASEINFORMATION stores every visit made by the patient to the hospital in the element VISITINFORMATION. The VISITINFORMATION has DATE,DOCTOR,COMPLAIN,DIAGNOSIS, PRESCRIPTION, and NEXTDATEOFVISIT. All the above files are in the same namespace and hence include element is used to include the definitions in commonschema.xsd in casehistory.xsd. Use the XML Schema Validator to validate the xml file against its schema. Casehistory.xml <pat1:CASEHISTORY xmlns:pat1="http://www.Getwellsoon.com/patient" CASESHEETID="C001"> John Watson
    24 <STREET>Wellington Road Seattle <STATE>Washington 55555
    MALE 10 <EXISTINGDISEASES>Diabetes
    2001-03-29 Diane Injury to the left knee caused heavy bleeding hematoma in left knee bed rest and change dressing twice a week 2001-04-07 2001-04-07 Diane Injury to the left knee caused heavy

    ©NIIT

    eXtensible Markup Language 51

    bleeding
    hematoma in left knee bed rest and change dressing twice a week 2001-04-14
    Casehistory.xsd <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.Getwellsoon.com/patient" xmlns:pat="http://www.Getwellsoon.com/patient"> <element name="CASEHISTORY"> <sequence> <element name="PERSONALINFORMATION" type="pat:dtpersonaldata"/> <element name="CASEINFORMATION" type="pat:dtcasedata"/> <sequence> <element name="NAME" type="string"/> <element name="ADDRESS" type="pat:dtaddress"/> <element name="GENDER" type="pat:dtgender"/> <element name="AGE" type="positiveInteger"/> <element name="EXISTINGDISEASES" type="string"/> <sequence> <element name="VISITINFORMATION" type="pat:dtdateofvisit" maxOccurs="unbounded"/> <sequence> <element name="DATE" type="date"/> <element name="DOCTOR" type="string"/> <element name="COMPLAIN" type="string"/> <element name="DIAGNOSIS" type="string"/> <element name="PRESCRIPTION" type="string"/> <element name="NEXTDATEOFVISIT" type="date"/>

    52 eXtensible Markup Language

    ©NIIT

    Commoninfo.xsd <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.Getwellsoon.com/patient" xmlns:pat="http://www.Getwellsoon.com/patient"> <simpleType name="dtcasesheetid"> <pattern value="[C]\d{3}"/> <sequence> <element name="HOUSENUMBER" type="string"/> <element name="STREET" type="string"/> <element name="CITY" type="string"/> <element name="STATE" type="string"/> <element name="ZIP" type="decimal"/> <simpleType name="dtgender"> <pattern value="(MALE|FEMALE)"/>

    2. The solution to the given scenario can be achieved using 2 files. Two xsd files and a xml file. The xsd files are: a. casehistory.xsl - This xsl file holds the transformation information to display the xml file. b. casehistory.xml - This xml file has CASEHISTORY as the root element with an ID "C001". The information in this xml file is grouped into two elements - PERSONALINFORMATION and CASEINFORMATION. The PERSONALINFORMATION stores the NAME,ADDRESS,GENDER,AGE, and EXISTINGDISEASES. The CASEINFORMATION stores every visit made by the patient to the hospital in the element VISITINFORMATION. The VISITINFORMATION has DATE,DOCTOR,COMPLAIN,DIAGNOSIS, PRESCRIPTION, and NEXTDATEOFVISIT. The xsl file displays the personal information of the patient in a list and the case related information in a table. Every visit of the patient to the doctor is displayed in a row along with all the information of the patients visit. Casehistory.xml John Watson
    24 <STREET>Wellington Road Seattle <STATE>Washington 55555


    ©NIIT

    eXtensible Markup Language 53

    MALE 10 <EXISTINGDISEASES>Diabetes
    2001-03-29 Diane Injury to the left knee caused heavy bleeding hematoma in left knee bed rest and change dressing twice a week 2001-04-07 2001-04-07 Diane Injury to the left knee caused heavy bleeding hematoma in left knee bed rest and change dressing twice a week 2001-04-14
    casehistory.xsl <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/"> <xsl:apply-templates/> <xsl:template match="/"> <xsl:apply-templates />, <xsl:template match="text()"> <xsl:value-of select="."/> <xsl:template match="EXISTINGDISEASES"> <xsl:if test="position()=last()”> . <xsl:template match="/"> <TITLE>Patient Information System

    Case History 2x5p4f

    <xsl:for-each select="CASEHISTORY/PERSONALINFORMATION"> Name: <xsl:value-of select="NAME"/>
    Address:
    HouseNumber: <xsl:value-of select="ADDRESS/HOUSENUMBER" />
    Street:<xsl:value-of select="ADDRESS/STREET" />


    54 eXtensible Markup Language

    ©NIIT

    City:<xsl:value-of select="ADDRESS/CITY" />
    State:<xsl:value-of select="ADDRESS/STATE" />
    Zip:<xsl:value-of select="ADDRESS/ZIP" />
    Gender: <xsl:value-of select="GENDER" />
    Age: <xsl:value-of select="AGE" />
    Existing Diseases: <xsl:apply-templates select="EXISTINGDISEASES" />

    <xsl:for-each select="CASEHISTORY/CASEINFORMATION/VISITINFORMATION">
    Date Doctor Complain Diagnosis Prescription Next Date of Visit
    <xsl:value-of select="DATE"/> <xsl:value-of select="DOCTOR"/> <xsl:value-of select="COMPLAIN"/> <xsl:value-of select="DIAGNOSIS"/> <xsl:value-of select="PRESCRIPTION"/> <xsl:value-of select="NEXTDATEOFVISIT"/>
    3. The solution to the given problem can be achieved using the xmldisplay.htm file. This html file displays a form that contains a text field and a hyperlink. The text field accepts the name of the xml file and clicking on the link invokes a function called cmdsubmit_click. This function is written using JavaScript. This JavaScript function instantiates the DOMDocument.4.0 class and obtains the reference of the object in to a variable xmldoc. Using the load(filename) method of DOMDocument class, the JavaScript function loads the xml file and using the xml property of the DOMDocument class displays the content of the xml file in a message box.

    ©NIIT

    eXtensible Markup Language 55

    trial.xml John John John John John XMLDisplay.htm XML 1u3p2l <meta http-equiv="Content-Type" content="text/html; charset=iso8859-1">
    Name of the XML File Submit

     

    <script Language="javascript"> function cmdSubmit_click() {if (frmPatient.TxtName.value.length==0) { alert ("Invalid File Name"); } else { var xmldoc= new ActiveXObject("Msxml2.DOMDocument.4.0"); xmldoc.load(frmPatient.TxtName.value); var error=xmldoc.parseError; if(error!="") { alert("error"); } else{ alert(xmldoc.xml); } }

    }

    56 eXtensible Markup Language

    ©NIIT

    4. You can create an HTML file to display a form that contains a text area and a hyperlink. The text area accepts a string from the . This string is then validated for its conformance as a well-formed xml. The needs to click the submit hyperlink to check it. The onclick event of the hyperlink is processed using a function written in JavaScript. This JavaScript function instantiates the DOMDocument.4.0 class and obtains the reference of the object in to a variable xmldoc. Using the loadxml(string) method of DOMDocument class, the JavaScript function loads the string entered by the . Using the parseError property of the DOMDocument class, the information about any errors in the xml document is retrieved into a variable called error. If there is no error, then the JavaScript function displays the entire string by using the xml property of the DOMDocument, else the JavaScript function displays error. XML 1u3p2l <meta http-equiv="Content-Type" content="text/html; charset=iso8859-1">
    Enter the XML String Here
    Submit

     

    <script Language="javascript"> function cmdSubmit_click() { if (frmPatient.TxtName.value.length==0) { alert ("Invalid XML String"); } else { var xmldoc= new ActiveXObject("Msxml2.DOMDocument.4.0"); xmldoc.loadXML(frmPatient.TxtName.value); var error=xmldoc.parseError; if(error!="") { alert("error"); } else {

    ©NIIT

    eXtensible Markup Language 57

    }

    alert(xmldoc.xml);

    } } 5. To create a text area for accepting XML tags, you need to create a Web page. The Web page displays a form that contains a text area and a hyperlink. The text area accepts a string from the . This string is then validated for its conformance as a well-formed xml. The needs to click the submit hyperlink to check it. The onclick event of the hyperlink is handled using a JavaScript function. This function instantiates the DOMDocument.4.0 class and obtains the reference of the object in to a variable xmldoc. Using the loadxml(string) method of DOMDocument class, the JavaScript function loads the string entered by the . Using the parseError property of the DOMDocument class, the information about any errors in the xml document is retrieved into a variable called error. If there is no error, a new element called “WELLFORMED” is created using the createElement(elementname) of the DOMDocument class. Using the documentElement property of the DOMDocument class, the JavaScript function obtains reference to root element of the xml document into a variable called rootnode. The JavaScript function then invokes the appendChild(elementname) function to attach the node to the root element. Using the text property of a node, the JavaScript function sets the text as good for the WELLFORMED element. The JavaScript function then sets the text of the textarea to the new xml string. XML 1u3p2l <meta http-equiv="Content-Type" content="text/html; charset=iso8859-1">
    Enter the XML String Here
    Submit

     

    <script Language="javascript"> function cmdSubmit_click() { var newelement; var rootnode; if (frmPatient.TxtName.value.length==0) { alert ("Invalid XML String"); 58 eXtensible Markup Language

    ©NIIT

    } else { var xmldoc= new ActiveXObject("Msxml2.DOMDocument.4.0");

    xmldoc.loadXML(frmPatient.TxtName.value); var error=xmldoc.parseError; if(error!="") { alert("error"); } else { rootnode=xmldoc.documentElement; newelement=xmldoc.createElement("WELLFORMED"); rootnode.appendChild(newelement); rootnode.lastChild.text = "good"; frmPatient.TxtName.value=xmldoc.xml } } }

    6. You can create an HTML file to display a form that contains a text area and a hyperlink. The text area accepts a string from the . This string is then validated for its conformance as a well-formed xml. The needs to click the submit hyperlink to check it. The code for creating the HTML page is given below: XML 1u3p2l <meta http-equiv="Content-Type" content="text/html; charset=iso8859-1">






    ©NIIT eXtensible Markup Language 59
    Enter the XML String Here
    Submit
    Reset

     

    <script Language="javascript"> function cmdSubmit_click() { var newelement; var rootnode; if (frmPatient.TxtName.value.length==0) { alert ("Invalid XML String"); } else { var xmldoc= new ActiveXObject("Msxml2.DOMDocument.4.0"); xmldoc.loadXML(frmPatient.TxtName.value); var error=xmldoc.parseError; if(error!="") { alert("error"); } else { rootnode=xmldoc.documentElement; newelement=xmldoc.createElement("WELLFORMED"); rootnode.appendChild(newelement); rootnode.lastChild.text = "good"; frmPatient.TxtName.value=xmldoc.xml } } } function cmdReset_click() { var deleteelements; var rootnode; if (frmPatient.TxtName.value.length==0) { alert ("Invalid XML String"); } else { var xmldoc= new ActiveXObject("Msxml2.DOMDocument.4.0"); xmldoc.loadXML(frmPatient.TxtName.value); var error=xmldoc.parseError; if(error!="") { alert("error"); } else

    60 eXtensible Markup Language

    ©NIIT

    {

    rootnode=xmldoc.documentElement;

    deleteelements=xmldoc.getElementsByTagName("WELLFORMED");

    }

    for (var ctr=0; ctr<deleteelements.length; ctr++) { rootnode.removeChild(deleteelements.item(ctr)); frmPatient.TxtName.value=xmldoc.xml

    }

    } }

    In the above HTML page, the onclick event of the hyperlink is handled by a function written in JavaScript. This function instantiates the DOMDocument.4.0 class and obtains the reference of the object in to a variable xmldoc. Using the loadxml(string) method of DOMDocument class, the JavaScript function loads the string entered by the . Using the parseError property of the DOMDocument class, the information about any errors in the xml document is retrieved into a variable called error. If there is no error then the JavaScript function creates a new element using the createElement(elementname) of the DOMDocument class creates a element named WELLFORMED. Using the documentElement property of the DOMDocument class, the JavaScript function obtains reference to root element of the xml document into a variable called rootnode. The JavaScript function then invokes the appendChild(elementname) function to attach the node to the root element. Using the text property of a node, the JavaScript function sets the text as good for the WELLFORMED element. The JavaScript function then sets the text of the textarea to the new xml string. This html page also provides another hyperlink called Reset. Clicking on this link, gets the list of nodes named WELLFORMED. The JavaScript function uses getElementsbyTagName(elementname) of the DOMDocument class. The JavaScript function then loops through the number of elements returned by the function and uses the removeChild function to remove the nodes. The JavaScript function then sets the text of the textarea to the new xml string. 7. The following XSLT style sheet can be used to display the average student.xsl - This XSLT style sheet uses XPath language to calculate the sum of marks obtained by the student in maths, socialstudies and science and divides it by 3 to get the average marks. Use the html file required to transform xpath/xsl/t syntax.
    student.xsl -- >

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/">

    STUDENT DETAILS

    STUDENT ID: <xsl:value-of select="MARKSSUMMARY/STUDENT/@ID"/>


    ©NIIT

    eXtensible Markup Language 61

    Maths Total: <xsl:value-of select='sum(//MARKSSUMMARY/STUDENT/TEST/MATHS) div 3'/>
    Science Total:<xsl:value-of select='sum(//MARKSSUMMARY/STUDENT/TEST/SCIENCE) div 3'/>
    Social Total:<xsl:value-of select='sum(//MARKSSUMMARY/STUDENT/TEST/SOCIALSTUDIES) div 3'/>



    student.xml -- >

    <MARKSSUMMARY> <STUDENT ID="S001"> <MATHS>90 <SCIENCE>100 <SOCIALSTUDIES>90 <MATHS>80 <SCIENCE>60 <SOCIALSTUDIES>75 <MATHS>70 <SCIENCE>70 <SOCIALSTUDIES>45 8. The languages for defining the structure of an xml document are DTD and XSD. 9. Which of the following is true? a.

    Simple Data types contain elements –false

    b.

    Complex data types contain elements, and attributes – true

    10. An object model that allows scripting languages to access and manipulate XML documents is known as Document Object Model.

    62 eXtensible Markup Language

    ©NIIT

    ADDITIONAL BOOK REFERENCES Erik .T Ray, Learning XML Steven Holzner, Inside XML Elliotte Rusty Harold, W. Scott Means, XML in a Nutshell: A Desktop Quick Reference John Duckett, Professional XML Schemas John Griffin, XML and SQL Server 2000 John Robert Gardner, Zarella .L Rendon, XSLT and XPATH: A Guide to XML Transformations Elliotte Rusty Harold, XML Bible Kurt Cagle, Beginning XML Mark Birbeck, Professional XML Paul .J Burke, Professional SQL Server 200 XML Paul Deitel, The Complete XML Training Course Graeme Malcom, Programming Microsoft SQL Server 2000 with XML Dave Mercer, XML: A Beginner's Guide Michael .J Young, Step by Step XML James Bean, XML Globalization and Best Practices: Using XML Schemas and XML Data

    ©NIIT

    eXtensible Markup Language 63

    LIST OF WEB SITES „Welcome to XML Spy! – http://www.xmlspy.com/

    „IONA XMLBUS – http://www.xmlbus.com/

    „XML From the Inside Out – http://www.xml.com/

    „Extensible Markup Language – http://www.w3.org/XML/

    „Java ™ Technology & XML – http://java.sun.com/xml/

    „DevX: XML Zonehttp://www.xml-zone.com/default1.asp?Area=XML

    „XML Tutorial – http://www.w3schools.com/xml/default.asp

    „WDVL: XML: Extensible Markup Language – http://wdvl.internet.com/Authoring/Languages/XML/

    „able Java-based Applications – http://www.ibm.com/java/apps/

    „Welcome to the Apache XML Project http://xml.apache.org/

    „DeveloperWorks: XML – http://www-106.ibm.com/developerworks/xml/

    „expat - XML Parser Toolkit – http://www.jclark.com/xml/expat.html

    „XML Global Technologies - Consulting – http://www.xmlglobal.com/consult/

    64 eXtensible Markup Language

    ©NIIT

    „XML Magazine – http://www.xmlmag.com/

    „WebDeveloper.com http://www.webdeveloper.com/xml/

    „Project Cool XML Zone – http://www.projectcool.com/developer/xmlz/

    „Xmlpitstop.com – http://www.xmlpitstop.com/

    „XML Script – XML Productivity Applications – http://www.xmlscript.org/

    „Introduction to DSSSL – http://www.prescod.net/dsssl/

    „The XML Cover Pages DSSSL - Document Style Semantics and Specification Language. ISO/IEC 10179:1996 –

    http://www.oasis-open.org/cover/dsssl.html

    „DSSSL Document Style Sheet Semantics and Specification Language http://www.netfolder.com/DSSSL/

    „SUN XML | FAQs http://www.sun.com/software/xml/faqs.html;$sessionid$BBTWYAIAAABJHAMTA1FU3NQ

    ©NIIT

    eXtensible Markup Language 65

    SESSION PLAN: EXTENSIBLE MARKUP LANGUAGE Cycle # Cycle1

    Activity/Problem No.

    Duration (In Mins)

    OCR1 Lesson 1: Objectives EDI and XML Components of XML document 1.P.1 Summary Total

    5 45 45 20 5 120

    Lesson 2: Objectives Using DTD JAM Using schemas 2.P.1 Summary Total

    5 50 10 20 25 10 120

    Lesson 3: Objectives Attributes in schema JAM Using namespaces Importing schemas JAM Summary Total

    2 40 10 10 25 10 8 105

    OCR2

    Cycle2 OCR1

    OCR2 Lesson 4: Objectives Create groups of elements and attributes in an XML schema JAM 4.P.2 Summary Total

    5 30 10 60 5 110

    Lesson 5: Objectives CSS JAM XSLT 5.P.1 Summary Total

    5 20 10 45 20 10 110

    Lesson 6: Objectives Conditional formatting

    5 15

    Cycle3 OCR1

    OCR2

    66 eXtensible Markup Language

    ©NIIT

    JAM XPath HTML in XSL/T 6.P.1 Nested style sheets Summary Total

    10 40 20 20 5 5 120

    Lesson 7: Objectives Introducing XML DOM 7.D.1 JAM Summary Total

    5 60 20 10 5 100

    Cycle 4 OCR1

    OCR2 Lesson 8: Objectives Validating an XML document against schema JAM Dynamically applying style sheets 8.P.1 Summary Total

    ©NIIT

    5 25 5 25 40 5 105

    eXtensible Markup Language 67

    Related Documents 3m3m1z

    Xml Realtime Examples 2t1b6x
    November 2021 0
    Xml k262e
    August 2020 0
    Xml k262e
    October 2022 0
    Petrel Realtime Geosteering 1a2c4k
    December 2021 0
    Xml Assignment 2b1q5f
    December 2019 37
    Leer Xml 641a18
    December 2022 0