Charlietn
asked on
How do I parse XML file in JAVA Script
I have an xml file created from a join. The XML file contains duplicates from the PARENT record.
Parent Name Parent Address Child Data
Parent Name Parent Address Child Data
Parent Name Parent Address Child Data
I can pull the child data but the duplicates throw me.
I need help with the code
Parent Name Parent Address Child Data
Parent Name Parent Address Child Data
Parent Name Parent Address Child Data
I can pull the child data but the duplicates throw me.
I need help with the code
ASKER
Thanks, Sorry for not posting the code. The XML file is attached as well as the code I use to make a table out of the child table. What I am having trouble with is the parent record.
Thanks for your patience. I am trying to learn by doing.
Charlie
Thanks for your patience. I am trying to learn by doing.
Charlie
<?xml version="1.0" encoding="windows-1252" standalone="yes" ?>
- <QUERY queryName="_QSQL560">
<Contract_no>123</Contract_no>
<Fname>Brandon</Fname>
<Lname>Thomas</Lname>
<Add1>123 ANY STR</Add1>
<City>Anytown</City>
<St>NC</St>
<Zip>29988</Zip>
<Tel>8888888888</Tel>
<Tel_2>9999999999</Tel_2>
<Club>The Club</Club>
<Email>bthomas@bthomas.com</Email>
<Contr_dt />
<Due_dt />
<LastCall_dt />
<Contract_no_1>123</Contract_no_1>
<CallDate>08/01/2011</CallDate>
<Rep>CDR</Rep>
<Disposition>N/A</Disposition>
<Note>Tried to call this person many times</Note>
<Contract_no>123</Contract_no>
<Fname>Brandon</Fname>
<Lname>Thomas</Lname>
<Add1>123 ANY STR</Add1>
<City>Anytown</City>
<St>NC</St>
<Zip>29988</Zip>
<Tel>8888888888</Tel>
<Tel_2>9999999999</Tel_2>
<Club>The Club</Club>
<Email>bthomas@bthomas.com</Email>
<Contr_dt />
<Due_dt />
<LastCall_dt />
<Contract_no_1>123</Contract_no_1>
<CallDate>08/02/2011</CallDate>
<Rep>LWOODY</Rep>
<Disposition>N/A</Disposition>
<Note>Customer is upset</Note>
<Contract_no>123</Contract_no>
<Fname>Brandon</Fname>
<Lname>Thomas</Lname>
<Add1>123 ANY STR</Add1>
<City>Anytown</City>
<St>NC</St>
<Zip>29988</Zip>
<Tel>8888888888</Tel>
<Tel_2>9999999999</Tel_2>
<Club>The Club</Club>
<Email>bthomas@bthomas.com</Email>
<Contr_dt />
<Due_dt />
<LastCall_dt />
<Contract_no_1>123</Contract_no_1>
<CallDate>08/10/2011</CallDate>
<Rep>TDAVIS</Rep>
<Disposition>L/M</Disposition>
<Note>Customer said to call when husband is home tonight</Note>
</QUERY>
Java to make disps tag into table
var xmlEl = response.getElementsByTagName("DISP");
var table = document.createElement("table");
table.border = "0";
table.width="95%";
table.align="CENTER";
var tbody = document.createElement("tbody");
// Append the body to the table
table.appendChild(tbody);
var row = document.createElement("tr");
// Append the row to the body
tbody.appendChild(row);
for (colHead = 0; colHead < xmlEl[0].childNodes.length; colHead++) {
if (xmlEl[0].childNodes[colHead].nodeType != 1) {
continue;
}
var tableHead = document.createElement("th");
var colName = document.createTextNode(xmlEl[0].childNodes[colHead].nodeName);
tableHead.align="left"
tableHead.style.fontFamily = "VERDANA";
tableHead.style.fontSize = "12px";
tableHead.style.backgroundColor = "#E0F2F5";
tableHead.appendChild(colName);
row.appendChild(tableHead);
}
tbody.appendChild(row);
// Create table row
for (i = 0; i < xmlEl.length; i++) {
var row = document.createElement("tr");
// Create the row/td elements
for (j = 0; j < xmlEl[i].childNodes.length; j++) {
// Skip it if the type is not 1
if (xmlEl[i].childNodes[j].nodeType != 1) {
continue;
}
// Insert the actual text/data from the XML document.
var td = document.createElement("td");
var xmlData = document.createTextNode(xmlEl[i].childNodes[j].firstChild.nodeValue);
if (i % 2) {
td.style.backgroundColor = "#E0F2F5";
}
td.style.fontFamily = "Verdana";
td.style.fontSize = "12px";
td.appendChild(xmlData);
row.appendChild(td);
}
tbody.appendChild(row);
}
document.getElementById("xmldata").appendChild(table);
--
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Had I posted a better question it would have been a perfect answer
What was the perfect answer?
I'd love to help you but I cannot find what you meant by parent
I'd love to help you but I cannot find what you meant by parent
ASKER
There wasn't one<G> I was making it more difficult than it was. Sorry for the poorly worded question.
Thanks again for your help. It is appreciated.
Thanks again for your help. It is appreciated.
Good. You had me worried there...
Try
var items = xmlDoc.getElementsByTagNam
for (var i=0,i<items.length;i<n;i++