SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 304 Weeks Ago, 6 Days Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 30 Oct 2017 My Price 9.00

Edit measurements2.html to add DOM parsing capabilities.

Hi, This is part 2 of the XML

 

-XML Applications Development

 

Take the file measurements1.html and copy it to measurements2.html. Edit measurements2.html to add DOM parsing capabilities.

 

Download the textbooks code from the Wrox web site and copy the zXml.src.js to your project folder.

Edit the measurements2.html file.

Within the head section of the html document, add these supporting script declarations, as well as these javascript function declarations:

 

<script type="text/javascript" src="/zXml.src.js"></script>

 

<script type="text/javascript">

 

function whatFile() {

 

var stringFile = document.form1.cmuds.value;

 

var oResults = document.getElementById("txtXml");

 

var fso = new ActiveXObject("Scripting.FileSystemObject");

 

var ts = fso.OpenTextFile(stringFile);

 

oResults.value += ts.ReadAll() + "n";

 

ts.Close();

 

}

 

function getDom() {

 

var oDom = null;

 

try {

 

oDom = new ActiveXObject("Msxml2.DomDocument.3.0");

 

}

 

catch (e) {

 

alert("This code needs msxml version 3 installed to operate.");

 

}

 

return oDom;

 

}

 

function getXml() {

 

return document.getElementById("txtXml").value;

 

}

 

function showParseError(err) {

 

var sMessage = "Error parsing input.nReason: " + err.reason + "nSource: " + err.srcText;

 

alert(sMessage);

 

}

 

function showResults(text) {

 

var oResults = document.getElementById("txtResults");

 

oResults.value += text + "n";

 

}

 

//The function countTotalMeasurements is counting how many measurement nodes are in the measurements1.xml file.

 

function countTotalMeasurements(dom){

 

}

 

//The function countMeasurements is counting how many nodes of a "typeOfMeasurement" are in the measurements1.xml file.

 

function countMeasurements(dom, measType){

 

}

 

//The function listElements outputs the values of the specific measure type for a specific element type (such as the value of all "weightType" of "troy").

 

function listElements(dom, measType, elementType){

 

}

 

function analyze() {

 

var oDom = getDom();

 

if (!oDom) return;

 

var bLoaded = oDom.loadXML(getXml());

 

if (!bLoaded) {

 

showParseError(oDom.parseError);

 

return;

 

}

 

var x = "measureDistance";

 

var y = "imperial";

 

var resultText = "The document element is: " + oDom.documentElement.nodeName + "n";

 

resultText += "There are " + countTotalMeasurements(oDom) + " measurement nodes in the filen";

 

resultText += "There are " + countMeasurements(oDom, "distanceType") + " distance measurements in the filen";

 

resultText += "There are " + countElements(oDom, x, y) + " " + y + " elements in the filen";

 

resultText += listElements(oDom, x, y);

 

y = "metric";

 

resultText += "There are " + countElements(oDom, x, y) + " " + y + " elements in the filen";

 

resultText += listElements(oDom, x, y);

 

resultText += "There are " + countMeasurements(oDom, "weightType") + " weight measurements in the filen";

 

x = "measureWeight";

 

y = "gram";

 

resultText += "There are " + countElements(oDom, x, y) + " " + y + " elements in the filen";

 

resultText += listElements(oDom, x, y);

 

y = "troy";

 

resultText += "There are " + countElements(oDom, x, y) + " " + y + " elements in the filen";

 

resultText += listElements(oDom, x, y);

 

showResults(resultText);

 

}

 

</script>

 

Within the body section, add this form after the text that already exists:

<form name=form1>

 

<input type=file name="cmuds">

 

<input type=button onClick="whatFile()" value="Open File"><br />

 

<textarea cols="80" rows="10" id="txtXml"></textarea><br />

 

<textarea cols="80" rows="10" id="txtResults"></textarea>

 

<br>

 

<input type="button" value="Analyze XML" onclick="analyze();">

 

</form>

 

Now fill in the functions countTotalMeasurements, countMeasurements, and the listElements.

Within these functions you should be using the DOM and Node properties to discover the information that each function is trying to find. You will be using things such as attributes, firstChild, childNodes and so forth.

When this is complete, you should be able to click the "Browse..." button, browse to your measurements1.xml file, click "Open", then click "Open File"

In the top box, you should have listed your xml file contents.

Example:

 

<measurements>

 

<measurement typeOfMeasurement ="distanceType">

 

<distance measureDistance="imperial">1.45</distance>

 

</measurement>

 

<measurement typeOfMeasurement ="weightType">

 

<weight measureWeight="troy">.6</weight>

 

</measurement>

 

<measurement typeOfMeasurement ="distanceType">

 

<distance measureDistance="metric">25</distance>

 

</measurement>

 

</measurements>

 

Click the "Analyze XML" button.

In the bottom box, the text from the analyze function should tell you:

 

How many total measurement nodes are in the file.

How many distance nodes are in the file.

How many imperial elements are in the file.

List the imperial values.

How many metric elements are in the file.

List the metric elements.

How many weight nodes are in the file.

How many gram elements are in the file.

List the gram elements.

How many troy elements are in the file.

List the troy elements.

Example:

 

The document element is: measurements

 

There are 3 measurement nodes in the file

 

There are 2 distance measurements in the file

 

There are 1 imperial elements in the file

Answers

(5)
Status NEW Posted 30 Oct 2017 01:10 PM My Price 9.00

-----------  ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly

Not Rated(0)