Reading XML Node_text using microsoft.xmldom

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AnuSumesh
    New Member
    • Aug 2007
    • 96

    Reading XML Node_text using microsoft.xmldom

    Hi,

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

    Code:
    <?xml version="1.0"?>
    
    <Domain_Credentials>
    	<User> anu </User>
    	<Password> admin </Password>
    	<SearchBaseDN> dc=def,dc=com </SerachBaseDN>
    	<Host> abc.def.com</Host>	
    </Domain_Credentials>
    I want to read the values of <user>,<passwor d> etc.

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

    Code:
                    file = "myfiles\DomainCredentials.xml"
                    file=Server.MapPath(file)
    	tag="Host"
    	Set fso =server.CreateObject("Scripting.FileSystemObject")
    If fso.FileExists(file) Then
    set doc = CreateObject("Microsoft.XMLDOM")
    
    	if err.number <> 0 or doc is nothing then
    		light_trace "error creating xmldom: " & err.description
    	else
    		light_trace "create xmldom ok"
    	end if
    
    	doc.async = "false"
    	doc.load(file)
    
    	if err.number <> 0 or doc is nothing then
    		light_trace "error loading xml file: " & err.description
    	else
    		light_trace "xml file load ok"
    	end if		        
                   Dim element
                   element=""
                   element=doc.GetElementsByTagName(tag).item(0).text
        end if
    My code failed at line "doc.GetElement sByTagName(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.GetElements ByTagName(tag). item(0).childno des(0).text also
    2. doc.selectsingl enode("/Domain_Credenti als/Host").text

    But no luck.

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

    Regards,
    anu
  • GazMathias
    Recognized Expert New Member
    • Oct 2008
    • 228

    #2
    What about:

    Code:
    doc.documentElement.childNodes(0).text
    Gaz.

    Comment

    Working...