MSXML SelectSingleNode returning all values

812 views Asked by At

When running this command:

objDoc.SelectSingleNode ("//ProfileSettings/Form[@name='frmViewMailMessages']/Control[@name='subMailMessages']/Height")

With objDoc's XML being:

<ProfileSettings>
    <Form name="frmViewMailMessages">
        <Control name="subMailMessages">
            <Height>4175</Height>
        </Control>
        <Control name="subMailMessage">
            <Height>4500</Height>
            <Top>3975</Top>
        </Control>
    </Form>
</ProfileSettings>

objDoc.Text returns a string containing all values appended:

417545003975

I'm trying to only receive the value 4175 from frmViewMailMessages->subMailMessages->Height

Any ideas? Thanks

1

There are 1 answers

1
Pankaj Jaju On BEST ANSWER

I think i know why .... you are using wrong object. Instead of using the objDoc, you need to set this into a Node and then retrieve the value. Something like the below

Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.SetProperty "SelectionLanguage", "XPath"
xmlDoc.Async = False
xmlDoc.Load("C:\Users\Pankaj\Desktop\test.xml")

Set nodeXML = xmlDoc.SelectSingleNode("//ProfileSettings/Form[@name='frmViewMailMessages']/Control[@name='subMailMessages']/Height")
msgbox nodeXML.Text