XML+HTML Code with sporadic results in construction

  • Thread starter christopher.davidson
  • Start date
C

christopher.davidson

Hello,

I am working with XML files and utilizing Array functions to take the
XML data and combined it with some html code to display a particular
page.

The process currently works like so:

1.) Request an Async request of the XML
2.) Once complete, parse the appropriate XML data to parse
3.) Put the html code and xml data into an array for construction
4.) Once parsing is complete "finish" the array and display within an
innerHTML tag

When I try to do this I get very sporadic results.

1.) Data being out of order from XML to the construction
2.) Replacing " or ' with ? within the code.


Listed below is the code in question, there is a comment stating

//not working

The code is looped through depending on the number of Tabs within the
page, pushing certain data to each tab section. The first page will be
malformed, the second page will be ok, the third is a hit or miss.

The XML data is not being changed in any respect through out this whole
process.

Any guidance will be greatly appreciated

Thank you for your time.


function displayReports() {
var htmlLayout;
var xmlPull = new getHTTPObject();
var url = "code/reportCatalog.xml";
var obj;

if (document.implementation && document.implementation.createDocument)
{
obj = document.implementation.createDocument("", "", null);
obj.async = false;
} else {
obj = new ActiveXObject("Microsoft.XMLDOM");
obj.async = false;
}

xmlPull.open("GET", url, true);
xmlPull.onreadystatechange = function() {
if (xmlPull.readyState == 4) {
if (xmlPull.status == 200) {
if (window.ActiveXObject) {
obj.loadXML(xmlPull.responseText);
for (var j = 0; j < TabCatalog.length; j++) {
htmlLayout = new Array();
htmlLayout[htmlLayout.length] = "<div id=\"reportList\">";

var pageString = (TabCatalog[j].pageName).toUpperCase();

for (var i = 0; i < obj.documentElement.childNodes.length; i++) {
var nodeList =
obj.documentElement.getElementsByTagName('report').item(i);

if (pageString.substring(0, (pageString.length - 5)) ==
nodeList.selectSingleNode('category').text) {
//not working right
htmlLayout[htmlLayout.length] = "<h3><a
onclick=displayInformation(\"" +
nodeList.selectSingleNode('title').text + "\", \"" +
nodeList.selectSingleNode('category').text + "\")></a>"+
nodeList.selectSingleNode('title').text +
"</h3>";

//if the group tag exists within the report then add the group
description
if (nodeList.selectSingleNode('group')) {
htmlLayout[htmlLayout.length] = "Group: " +
nodeList.selectSingleNode('group').text + " <br/>";
}
htmlLayout[htmlLayout.length] = "<i>" +
nodeList.selectSingleNode('description').text +
"</i>";
htmlLayout[htmlLayout.length] = "Create Date:" +
nodeList.selectSingleNode('createdate').text +
"<br />";
}
}
htmlLayout[htmlLayout.length] = "</div>";
document.getElementById('panel_' +
TabCatalog[j].pageId).innerHTML = htmlLayout.join("");
//added for debugging purposes
alert(document.getElementById('panel_' +
TabCatalog[j].pageId).innerHTML);
}
}
}
delete htmlLayout, nodeList, pageString;
populatePreviewArea();
}
};
xmlPull.setRequestHeader("Content-Type", "text/xml; charset=UTF-16");
xmlPull.send(null);
}
 
V

VK

Hello,

I am working with XML files and utilizing Array functions to take the
XML data and combined it with some html code to display a particular
page.

The process currently works like so:

1.) Request an Async request of the XML
2.) Once complete, parse the appropriate XML data to parse
3.) Put the html code and xml data into an array for construction
4.) Once parsing is complete "finish" the array and display within an
innerHTML tag

When I try to do this I get very sporadic results.

1.) Data being out of order from XML to the construction
2.) Replacing " or ' with ? within the code.


Listed below is the code in question, there is a comment stating

//not working

The code is looped through depending on the number of Tabs within the
page, pushing certain data to each tab section. The first page will be
malformed, the second page will be ok, the third is a hit or miss.

The XML data is not being changed in any respect through out this whole
process.

Holly... Did you ever hear about XSLT? XPath?

data.xml :
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="catalog.xsl"?>
....
and so on
 
C

Christopher.Davidson

yes i have heard of it VK, but at this time I do not understand it very
well. My approach would be to learn how to do it manually. Once this
works proceed to reimplement this with XSL and XPath.
 
C

Christopher.Davidson

After much debugging I have found the solution and felt it best to post
the solution, for other people to learn from.

//not working right
htmlLayout[htmlLayout.length] = "<h3><a
onclick=\'displayInformation(\"" +
nodeList.selectSingleNode('title').text
+ "\"" + ", " + "\"" +

nodeList.selectSingleNode('category').text + "\"" + "," +
"\"" + TabCatalog[j].pageName + "\"" +
");\'>" +
nodeList.selectSingleNode('title').text
+ "</a></h3>";

the single quote had to be implemented to allow the double quotes to
not bring up the issues of mistmatch string termination.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,122
Latest member
VinayKumarNevatia_
Top