473,394 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Why don't I get the node value of the code node?

108 100+
I just happened to learn abt xml DOM.....I tried this script and run it bt didnt get the desired result..I expected to get the value I attached to my code node bt what I gt ws null which means that I went wrong somewhere in my script....


Expand|Select|Wrap|Line Numbers
  1. <html>
  2.     <head>
  3.         <script type='text/javascript'>
  4.             xml_modules="<modules><module><code></code></module></modules>";
  5.             var xml_modules;
  6.  
  7.             function addxml(url)
  8.  
  9.                 {
  10.                     var xmlDoc;
  11.                     try{
  12.                         xmlDoc=new ActiveXObject('Microsoft.XMLDOM');
  13.                         xmlDoc.async='false';
  14.                         xmlDoc.loadXML(url);
  15.                         return xmlDoc;
  16.                     }
  17.                     catch(e){
  18.  
  19.                         try {
  20.                             parser=new DOMParser();
  21.                             xmlDoc=parser.parseFromString(url,'text/xml');
  22.                             xmlDoc.encoding='UTF-8';
  23.                             return xmlDoc;
  24.                             }catch(e) {alert(e.message);}
  25.                         }
  26.                         return (null);
  27.  
  28.                 } 
  29.                 var xml_Doc_modules=addxml(xml_modules);
  30.  
  31.                 function textxml()
  32.                     {
  33.  
  34.                         root=xml_Doc_modules.childNodes[0];
  35.                         a=xml_Doc_modules.createTextNode('node1');
  36.  
  37.                         root.childNodes[0].childNodes[0].appendChild(a)    ;
  38.  
  39.                         alert(root.childNodes[0].childNodes[0].nodeValue);
  40.  
  41.  
  42.  
  43.                     } 
  44.  
  45.  
  46.         </script>
  47.     </head>
  48. <body>
  49. <button onclick='textxml()'>ProcessXml</button>
  50.  
  51. </body>

This is the script....!!!!
I went wrong somewhere in my codes bt cant guess where....
Can u tell me where I went wrong and how can I attach a value to a node ??


Thanks in adv

With regards
phpuser123
Apr 17 '10 #1
7 1772
phpuser123
108 100+
I jst happened to learn abt xml DOm...For trial purposes i implemented this script
..
Expand|Select|Wrap|Line Numbers
  1. <html>
  2.     <head>
  3.         <script type='text/javascript'>
  4.             var xml_modules;
  5.             xml_modules="<modules><module><code></code><tbl></tbl></module></modules>";
  6.             var xml_Doc_modules=loadString(xml_modules);
  7.             function loadString(txt)
  8.                     {
  9.                         var xml_Doc;
  10.                         try{
  11.                             xmlDoc=new ActiveXObject("Microsoft.XMLDOM")    ;
  12.                             xml_Doc.async="false";    
  13.                             xml_Doc.loadXML(txt);
  14.                             return xml_Doc;
  15.                             }
  16.                         catch(e)
  17.                             {
  18.                                 try{
  19.                                     parser=new DOMParser();
  20.                                     xml_Doc=parser.parseFromString(txt,"text/xml");    
  21.                                     xml_Doc.encoding='UTF-8';alert('sad');
  22.                                     return xml_Doc;
  23.  
  24.                                 }
  25.                                 catch(e){
  26.                                         alert(e.message);
  27.                                     }
  28.  
  29.                             }
  30.                         return (null);
  31.                     }
  32.  
  33.  
  34.                 function testxml(){
  35.                         root=xml_Doc_modules.childNodes[0];
  36.                         code_tbl=xml_Doc.createTextNode('tbl1');
  37.                         code_text=xml_Doc_modules.createTextNode('code1');
  38.                         root.childNodes[0].childNodes[1].appendChild(code_tbl);alert(code_tbl.nodeValue);
  39.                         root.childNodes[0].childNodes[0].appendChild(code_text);alert(code_text.nodeValue);
  40.  
  41.  
  42.                         }
  43.         </script>
  44.     <body>
  45.         <button onclick='testxml()'>Preess me</button>
  46.     </body>
  47.     </html>
What i expect to see when I press my button is the value of my two nodes code and tbl....But the script is nt working .Somehow i managed to find out that the problem is with this line

code_tbl=xml_Doc.createTextNode('tbl1');


I dnt know what's the problem,cn u enlighten me with this ???

Thanks in adv


With regards

phpuser123
Apr 18 '10 #2
Dormilich
8,658 Expert Mod 8TB
what does the error console say?
Apr 18 '10 #3
jkmyoung
2,057 Expert 2GB
Is the response from your url valid xml, and does it get parsed correctly?
Do you know that root.childNodes[0].childNodes[0] exists?
Apr 19 '10 #4
Dormilich
8,658 Expert Mod 8TB
it is recommended to use xml_Doc.documentElement to get the root. the firstChild may point to whitespace, the DTD or other processing instructions.
Apr 19 '10 #5
phpuser123
108 100+
That's the problem the console doesnt sayy anythng...
I dont gt any alert box ....
When I happen to remove line 36 and line 38,I get my nodeValue of the code...
When i remove line 39 and 37,there is no alert box...
R there any prob in the lines 36 and 38 ?
Apr 19 '10 #6
Dormilich
8,658 Expert Mod 8TB
then why not using document.createTextNode() ?
Apr 19 '10 #7
phpuser123
108 100+
Yeps i'lll try this one ...
Bt some miracle happened,the above script started working all by itself...
I dnt know hw this happened......
Apr 19 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Keith M | last post by:
Hi, I have found a very useful piece of code in the msdn which shows how to load an xml config file, search for a particular value and replace it. Could someone possibly convert it to C# from...
1
by: David | last post by:
All I am using the code below in order to read an XML file in the format: <root> <selection-attr attr="p70"> <value code="Mr">Mr</value> <value code="Mrs">Mrs</value> <value...
1
by: Dica | last post by:
hi all first off, i'm not trying to cross post, but couldn't find this newsgroup earlier (got here from a recommendation on microsoft.public.vb, where i originally posted this question). ...
0
by: XML newbie: Urgent pls help! | last post by:
HI, I am working on VB.Net.My program connects to the remote host, once the login values are verified, it sends the SessionID. My problem is Although in "Logindom" variable( in the Auto window),...
1
by: John Wilhelm | last post by:
I'm having a problem in by VB.net 2005 application. When i try to get a node from my app.config file the node come back with "nothing". The xmldocment loads OK, but I can't retrive a node. The...
2
by: daz_oldham | last post by:
Hi everyone An easy one I think, I am just not too sure of the best way of going about this. I have the following XmlNode as an example: <people group="33" status="334kdnsfins435" value"x">...
2
by: Tjerk Wolterink | last post by:
I have a variable $value as a parameter in the following template: <xsl:template name="myTemplate"> <xsl:param name="value"/> <xsl:if test="$value"> <xsl:value-of select="$value"/> </xsl:if>...
10
by: Simon Brooke | last post by:
The DOM API has included public Node importNode(Node,boolean) as a method of the Document interface for a long time. Does anything actually implement it? Xerces 2 is giving me: ...
2
jkmyoung
by: jkmyoung | last post by:
Here's a short list of useful xslt general tricks that aren't taught at w3schools. Attribute Value Template Official W3C explanation and example This is when you want to put dynamic values...
20
omerbutt
by: omerbutt | last post by:
hi there i am making an application in which i have to populate columns that consist of some textfields and some input boxes the problem is at the mozilla's end, it creates a new node and appends the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.