470,572 Members | 1,916 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,572 developers. It's quick & easy.

Reading XML Node_text using microsoft.xmldom

AnuSumesh
Hi,

I want to read the text property of XML file.
My xml file is as follows:

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2.  
  3. <Domain_Credentials>
  4.     <User> anu </User>
  5.     <Password> admin </Password>
  6.     <SearchBaseDN> dc=def,dc=com </SerachBaseDN>
  7.     <Host> abc.def.com</Host>    
  8. </Domain_Credentials>
  9.  
I want to read the values of <user>,<password> etc.

For reading these values, my code is as follows(in asp file):

Expand|Select|Wrap|Line Numbers
  1.                 file = "myfiles\DomainCredentials.xml"
  2.                 file=Server.MapPath(file)
  3.     tag="Host"
  4.     Set fso =server.CreateObject("Scripting.FileSystemObject")
  5. If fso.FileExists(file) Then
  6. set doc = CreateObject("Microsoft.XMLDOM")
  7.  
  8.     if err.number <> 0 or doc is nothing then
  9.         light_trace "error creating xmldom: " & err.description
  10.     else
  11.         light_trace "create xmldom ok"
  12.     end if
  13.  
  14.     doc.async = "false"
  15.     doc.load(file)
  16.  
  17.     if err.number <> 0 or doc is nothing then
  18.         light_trace "error loading xml file: " & err.description
  19.     else
  20.         light_trace "xml file load ok"
  21.     end if                
  22.                Dim element
  23.                element=""
  24.                element=doc.GetElementsByTagName(tag).item(0).text
  25.     end if
  26.  
My code failed at line "doc.GetElementsByTagName(tag).item(0).text".
Earlier a long time back, This code was working fine.
But now giving error.
And also please tell me how to retreive the error description for this line in asp?

I have tried following options also:
1. doc.GetElementsByTagName(tag).item(0).childnodes(0 ).text also
2. doc.selectsinglenode("/Domain_Credentials/Host").text

But no luck.

Can anyone please help me how to read these values from given xml file?

Regards,
anu
May 20 '09 #1
1 4074
GazMathias
228 Expert 128KB
What about:

Expand|Select|Wrap|Line Numbers
  1. doc.documentElement.childNodes(0).text
  2.  
Gaz.
May 26 '09 #2

Post your reply

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

Similar topics

4 posts views Thread by VK | last post: by
2 posts views Thread by kmunderwood | last post: by
2 posts views Thread by Kenneth | last post: by
1 post views Thread by =?Utf-8?B?WmFnb3I=?= | last post: by
2 posts views Thread by Joey Martin | last post: by
1 post views Thread by livre | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.