Click to See Complete Forum and Search --> : Help needed: how can I substitute xml data islands?
pbuongiovanni
02-21-2005, 01:13 PM
Hi,
I am looking a valid solution to substitute xml data islands in HTML pages. As you know, xml data island is the mechanism used to call xml parser in HTML pages and load XML files. This valid mechanism is very useful but not portable. It works very well with IE, but it doesn't works with Mozilla (for example). I am looking for a portable solution, so I cannot use xml data islands as a final solution.
Could someone give me another valid solution?
Please remember I must load data from several XML files, so I cannot use the solution of XSL Style Sheet files, because I cannot match files 1 to 1. With xml data islands I can use JavaScript and ad hoc function to load data in sections of HTML pages.
I studied XML language in "XML by examples" but this book has been printed in 2000. So I think something could be changed and a different solution could be used instead of xml data islands.
Many thanks in advance.
Piergiorgio Buongiovanni
piergiorgio_buongiovanni@hotmail.com
Khalid Ali
02-21-2005, 01:48 PM
you canimport an XML file in mozilla based browsers just like you would in IE here is an example (http://www.webapplikations.com/pages/html_js/xmlstuff/XMLHttpRequest.html) of such solution. It works for bot IE and Mozilla based browsers.
Note. XML files must be served from the same server/domain where you calling pages are
pbuongiovanni
02-22-2005, 07:35 AM
Hi Khalid,
many thanks for your suggestion. I understand the only possible solution is cabling the code and identifying the browser, in order to call the correct method. Yes, this is a possibility... I agree with you. I am not hardly experienced in XML programming and I don't know if there are other possibilities but, as per your response, I think no.
I hope to have the possibility to study other techniques in future... many thanks and best regards.
Piergiorgio
pbuongiovanni
03-02-2005, 04:37 PM
Originally posted by Khalid Ali
you canimport an XML file in mozilla based browsers just like you would in IE here is an example (http://www.webapplikations.com/pages/html_js/xmlstuff/XMLHttpRequest.html) of such solution. It works for bot IE and Mozilla based browsers.
Note. XML files must be served from the same server/domain where you calling pages are
Hi Khalid,
I tried to use your example above, but - as per my last note - I found problem to substituting your file classpath.xml with mine (an example). Probably I introduced an error, but when I try to parse the xml file, I have 0 nodes. I don't understand the reason of this behaviour. Could you please send your file classpath.xml to me?
Many thanks in advance.
Kind regards.
Piergiorgio
Khalid Ali
03-02-2005, 05:17 PM
here is the content of that file just save it as classpath.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<Path>
<Jar name="activation-1.0.2.jar" path="C:\jakarta-tomcat-4.1.18\webapps\pegarules\WEB-INF\lib">
<Class_path>javax/activation/SecuritySupport12.class</Class_path>
</Jar>
<Jar name="AddressBook.jar" path="C:\jakarta-tomcat-4.1.18\webapps\pegarules\WEB-INF\lib">
<Class_path>PREJBSample/AddressBook.class</Class_path>
<Class_path>PREJBSample/ThirdBook.class</Class_path>
<Class_path>PREJBSample/FourthBook.class</Class_path>
<Class_path>PREJBSample/FifthBook.class</Class_path>
<Class_path>PREJBSample/SixthBook.class</Class_path>
</Jar>
</Path>
pbuongiovanni
03-04-2005, 09:06 AM
Hi Khalid,
many thanks for the file classpath.xml. Finally I have been able to test the code and I have found a different behaviour between MSIE 6.0 and Mozilla.
Pratically the code works with Mozilla but it doesn't work with MSIE 6.0. The behaviour is strange but, I have modified the code as below in order to have some indication and to ask you if you know the reason of this difference.
Please look at the code (JS):
function Process(){
//first create httprequest object
dhtml="<table style=\"width:600px;\" cellspacing=\"2\" cellpadding=\"2\" border=\"1\">"+
"<tbody>"+
"<tr>"+
" <th style=\"width:160px;\">Jar Name</th>"+
" <th style=\"width:440px;\">Class Paths</th>"+
"</tr>";
try{
xmlhttpDoc = new ActiveXObject("Msxml2.XMLHTTP");
alert ( "Using Msxml2.XMLHTTP" );
}catch (e){
try{
xmlhttpDoc = new ActiveXObject("Microsoft.XMLHTTP");
alert ( "Using Microsoft.XMLHTTP" );
}catch(e){
xmlhttpDoc = new XMLHttpRequest();
alert ( "Using XMLHttpRequest" );
}
}
xmlhttpDoc.open("GET","classpath.xml",true);
xmlhttpDoc.onreadystatechange = StartParsing;
xmlhttpDoc.send(null); //make sure that you used this line of code.
}
function StartParsing(){
if(xmlhttpDoc.readyState==4){
alert ( "StartParsing called and readyState=4!" );
var xmlDoc = (xmlhttpDoc.responseXML);
alert ( xmlhttpDoc.responseXML );
alert ( xmlhttpDoc.responseText );
alert ( xmlhttpDoc.responseBody );
ParseXML(xmlDoc.childNodes,"Class_path");
document.getElementById("dynamcHTML").innerHTML = dhtml;
}
}
function ParseXML(nodes,name){
var tempArr = new Array();
alert ( nodes.length );
for(var x=0;x<nodes.length;x++){
var node = nodes[x];
if(node.nodeType==1 && node.nodeName=="Jar"){
ProcessNode(node);
}else if(node.nodeType==1 && node.childNodes.length>0){
ParseXML(node.childNodes,name);
}
}
}
As you can see, I simply inserted some "alert" functions in order to debug the code.
Executing the code with the browser Mozilla I obtained the following output:
1) Using XMLHttpRequest
2) StartParsing called and readyState=4!
3) [object XMLDocument] <-- alert ( xmlhttpDoc.responseXML );
4) the xml file <-- alert ( xmlhttpDoc.responseText );
5) empty <-- alert ( xmlhttpDoc.responseBody );
6) 1 <-- first call of alert ( nodes.length ); in ParseXML method
Executing the code with the browser MSIE 6.0 I obtained the following output:
1) Using Msxml2.XMLHTTP
2) StartParsing called and readyState=4!
3) [object] <-- alert ( xmlhttpDoc.responseXML );
4) the xml file <-- alert ( xmlhttpDoc.responseText );
5) a lot of bytes <-- alert ( xmlhttpDoc.responseBody );
6) 0 <-- first call of alert ( nodes.length ); in ParseXML method
As you can see, the major differences are points 3) and 6).
I know that using Msxml2.XMLHTTP an object IXMLHTTPRequest is created, but when I execute alert ( xmlhttpDoc.responseXML ); I have no object defined. Then I have 0 reading nodes.length and as result the example doesn't work, because reading 0 nodes, the final table is not dinamically created!
Do you have any suggestion? Why this difference in the behavior of the same code with different browsers? Now I have an other problem, because I have solved the problem with Mozilla, but I have a new one with MSIE.
Could you please suggest me a workaround for this matter or give me a reason for this behaviour.
Kind regards.
Piergiorgio
Khalid Ali
03-04-2005, 01:58 PM
if you implement the code example I directed you to (the url) you should have the code that works on both IE and Mozilla, the typical problem is that mozilla sees a text node in every node where as IE does not
pbuongiovanni
03-08-2005, 12:06 PM
Hi Khalid,
I appreciated your reply but I assure that the code you posted doesn't work with MS IE 6.0 SP1. As you can see looking at the part of code I attached to my previous message, I haven't changed the original code: I have added only some alert messages in order to debug the code using Mozilla, Netscape and MS IE 6.0 SP1. I confirm I have no problem with the first two browsers.
However I have tried to find a solution to my problem and I am happy to inform you that I have found it. I have used a mixed solution: xml data island + XMLHTTPRequest object. I used DOM XML Document's method (load) to read the xml file, inserting a xml data island at the end of the DHTML page. So only a little part of code is browser-specific: I wrote a function (Load) that first checks the type of browser and then it splits the the code using the proper method.
I have successfully tested the code and I have definitely solved my problem: now I am able to load data from different xml files in HTML/DHTML pages.
With reference to your latest e-mail where you assert that the code you have posted works in both MS IE and Mozilla, I would understand how it's possible because my tests confirm that it's not true. As you can remember, I asked you to send your xml test file classpath.xml to me, because I was not able to test your code with MS IE 6.0. When I received your xml file, I tried to test your example but it didn't work. So I passed to Mozilla (and I also installed Netscape) to verify the code and I saw it worked without problems. My final conclusion was that your code don't work properly in MS IE 6.0 SP1, and the debug session confirmed my thought.
If you have other suggestions to debug/understand the reason of problem, please reply to me. I am happy to test/verify and find a solution.
Kind regards.
Piergiorgio Buongiovanni
Khalid Ali
03-09-2005, 01:59 PM
Originally posted by pbuongiovanni
Hi Khalid,
My final conclusion was that your code don't work properly in MS IE 6.0 SP1, and the debug session confirmed my thought.
Kind regards.
Piergiorgio Buongiovanni
;)
thats all right.
I know that I have used this code in production for last couple of years,
I know that it work on Mozilla(1.4 an above) based browsrs.
I know for utmost certainty that it works for IE as well I have personally tested it in IE 6.0.18xxx SP1 on windows XP professional as well as windows 2000.
Here is the link again open it up in your IE and see if works or not
http://www.webapplikations.com/pages/html_js/xmlstuff/XMLHttpRequest.html
Other then that if you have solved your problem then thats even better we just intend to guide and help and I am glad if I could help or guide..
Oh by the way if the link above doesn't work in your browser then it has to be a problem with your setup.
pbuongiovanni
03-10-2005, 01:23 PM
Originally posted by Khalid
Oh by the way if the link above doesn't work in your browser then it has to be a problem with your setup.
Khalid
Hi Khalid,
I understand your conclusions... and I understand that you used your code on several projects. Please consider I am looking at XML only by few months, but I am very interested. This is the reason that convinced me to go forward and to find a solution.
My main problem is that reading nodes with MS IE 6.0, I find 0 nodes. Please look at my previous reply to you: I hope it's clear:
The function below:
function ParseXML(nodes,name){
var tempArr = new Array();
alert ( nodes.length );
for(var x=0;x<nodes.length;x++){
var node = nodes[x];
if(node.nodeType==1 && node.nodeName=="Jar"){
ProcessNode(node);
}else if(node.nodeType==1 && node.childNodes.length>0){
ParseXML(node.childNodes,name);
}
}
}
prints 0 <-- first call of alert ( nodes.length );
This is the problem: I don't know why Mozilla returns 1 (the first node).
What do you think about the configuration of my browser?
Could you suggest any checks?
Cheers.
Piergiorgio
Khalid Ali
03-10-2005, 01:26 PM
put the page you are working on a webserver and post here th eurl to it I will see what is going on, if it doesn't work for u I bet it will not work for any other browser as well that will help me see whats wrong at your end that is breaking the code.
pbuongiovanni
03-14-2005, 01:03 PM
put the page you are working on a webserver and post here th eurl to it I will see what is going on, if it doesn't work for u I bet it will not work for any other browser as well that will help me see whats wrong at your end that is breaking the code.
Hi Khalid,
I understand your suggestion and I think the problem is the webserver: it's clear that the code requires a webserver, but the other browsers work properly without a webserver installed. If I test my pages, I don't need a webserver: I am working locally.
Now it's clear: the problem is the presence of a webserver.
Please note that the xml data island mechanism doesn't require a webserver to work: I can test my pages without a webserver.
Do you agree with me?
Cheers.
Piergiorgio