Hello,
I'm trying to understan how DOM works.
I have xml etc.:
To select file "file2.txt" I use this code:Code:<root> <file> <Filename>file1.txt</Filename> <Atributes> <Atribute>ReadOnly</Atribute> <Atribute>Hidden</Atribute> </Atributes> </file> <file> <Filename>file2.txt</Filename> <Atributes> <Atribute>Hidden</Atribute> </Atributes> </file> </root>
VB Code:
Dim oXMLDoc As MSXML2.DOMDocument40 Dim oXMLNode As MSXML2.IXMLDOMNode Dim oXMLNodeList As MSXML2.IXMLDOMNodeList Set oXMLDoc = New MSXML2.DOMDocument40 oXMLDoc.async = False oXMLDoc.resolveExternals = True oXMLDoc.Load ("C:\files.xml") oXMLDoc.setProperty "SelectionLanguage", "XPath" Set oXMLNodeList = oXMLDoc.selectNodes("/root/file[Filename='file2.txt']") If oXMLNodeList.length <> 1 Then exit sub 'there is 0 or more files with same filename else 'now I want to read all atributes to string For Each oXMLNode In oXMLNodeList(0).selectNodes("//Atribute") Atributes = Atributes & oXMLNode.Text & ", " Next end if
It retunrs "ReadOnly, Hidden, Hidden, " but not only result for that file ("Hidden")
I do know want to use loops, becourse it must be as fast as can be.




Reply With Quote