Connecting Tech Pros Worldwide Forums | Help | Site Map

String to XML

RamananKalirajan's Avatar
Needs Regular Fix
 
Join Date: Mar 2008
Location: Chennai - India
Posts: 350
#1: Mar 7 '08
I am currently working on a Typical Project, in which I have a requirement such that i have to fetch a data which is in CLOB format that holds XML Element. I am passing that value as a String to Javascript through AJAX. My need is I have to convert that String to XML or use that String and print the XML data in a Table dynamically Please can any one help me in doing so

Thank You,
Ramanan

acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: Mar 7 '08

re: String to XML


If you're using Ajax, make sure the XML is valid and use responseXML.

If you have problems, post your code.
RamananKalirajan's Avatar
Needs Regular Fix
 
Join Date: Mar 2008
Location: Chennai - India
Posts: 350
#3: Mar 10 '08

re: String to XML


Quote:

Originally Posted by acoder

If you're using Ajax, make sure the XML is valid and use responseXML.

If you have problems, post your code.


Thank you very much sir, I had did this by using the following code

Expand|Select|Wrap|Line Numbers
  1. var temp=http.getAttribute("empxml");
  2. if (window.ActiveXObject)
  3.   {
  4.   var doc=new ActiveXObject("Microsoft.XMLDOM");
  5.   doc.async="false";
  6.   doc.loadXML(temp);
  7.  alert("converted");
  8.   }
  9. // code for Mozilla, Firefox, Opera, etc.
  10. else
  11.   {
  12.   var parser=new DOMParser();
  13.   var doc=parser.parseFromString(temp,"text/xml");
  14.   }
  15.  
  16.  
  17. var _root = doc.getElementsByTagName("emp").item(0);
  18. var rows = _root.getElementsByTagName("pname");
  19. var projName=rows[0].firstChild.nodeValue;
  20. alert(projName);
  21. document.getElementById("pname").innerHTML=projName;
  22. var release=_root.getElementsByTagName("r");
  23.  
  24.     var _dhtml="<select name='relsel' id='relsel'>";    
  25.             for(var _n=0;_n<release.length;_n++)
  26.             {
  27.                 alert( release[_n].firstChild.nodeValue);
  28.                 _dhtml+="<option val='"+_n+"'>"+ release[_n].firstChild.nodeValue+"</option>";
  29.  
  30.             }
  31.     _dhtml+="</select>"
  32.  
  33.     document.getElementById("reldiv").innerHTML=_dhtml;
  34. }

Thank you
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#4: Mar 10 '08

re: String to XML


OK, so what happens with that code? How much of it is working as you want? What's not working? What errors have you got if any?
RamananKalirajan's Avatar
Needs Regular Fix
 
Join Date: Mar 2008
Location: Chennai - India
Posts: 350
#5: Mar 11 '08

re: String to XML


Quote:

Originally Posted by acoder

OK, so what happens with that code? How much of it is working as you want? What's not working? What errors have you got if any?


It's working good I am not having any error on it. Thank You Sir
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#6: Mar 11 '08

re: String to XML


Quote:

Originally Posted by RamananKalirajan

It's working good I am not having any error on it. Thank You Sir

Oh right. I misunderstood your post. Glad to see that it's working.
Reply