How can I accesss a value from a node?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • phpuser123
    New Member
    • Dec 2009
    • 108

    #1

    How can I accesss a value from a node?

    Code:
    <html>
    	<head>
    		<script type='text/javascript'>
    			var xml_modules;
    			xml_modules="<modules><module><code></code><tbl></tbl></module></modules>";
    			var xml_Doc_modules=loadString(xml_modules);
    			function loadString(txt)
    					{
    						var xml_Doc;
    						try{
    							xmlDoc=new ActiveXObject("Microsoft.XMLDOM")	;
    							xml_Doc.async="false";	
    							xml_Doc.loadXML(txt);
    							return xml_Doc;
    							}
    						catch(e)
    							{
    								try{
    									parser=new DOMParser();
    									xml_Doc=parser.parseFromString(txt,"text/xml");	
    									xml_Doc.encoding='UTF-8';alert('sad');
    									return xml_Doc;
    									
    								}
    								catch(e){
    										alert(e.message);
    									}
    								
    							}
    						return (null);
    					}
    					
    
    				function testxml(){
    						root=xml_Doc_modules.childNodes[0];
    						code_text1=document.createTextNode('codel');
    						code_text=document.createTextNode('tbl');
    						root.childNodes[0].childNodes[1].appendChild(code_text);alert(root.childNodes[0].childNodes[0].nodeValue);
    						root.childNodes[0].childNodes[0].appendChild(code_text);alert(root.childNodes[0].childNodes[1].nodeValue);
    						}
    		</script>
    	<body>
    		<button onclick='testxml()'>Preess me</button>
    	</body>
    	</html>
    I jst implemented this script...I jst want o diaplay the values i jst appended to thsoe nodes...
    I am getting a nulll value alll the time ....
    Hw cn i solve this problem ???


    Thanks in adv
    With regards
    Phpuser123
    Last edited by Dormilich; Apr 19 '10, 07:50 PM. Reason: Please use [code] tags when posting code
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    are you sure you didn’t mix up some indices?

    Firebug can help you digging through your XML document.

    Comment

    • jkmyoung
      Recognized Expert Top Contributor
      • Mar 2006
      • 2057

      #3
      The node values of that entire structure will be the blank string, not null.
      Are you looking for nodeValue or nodeName?
      You've definitely messed up some indices otherwise.

      Comment

      Working...