By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,759 Members | 1,244 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,759 IT Pros & Developers. It's quick & easy.

XML+HTML Code with sporadic results in construction

P: n/a
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);
}

Mar 8 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
VK

ch******************@gmail.com wrote:
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

Mar 8 '06 #2

P: n/a
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.

Mar 8 '06 #3

P: n/a
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.

Mar 8 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.