![]() |
Excel 2003 : Problem accessing childnodes in XMLDomElements
Hello,
Calling out for help... I've been searching and still clueless about this one... I'm trying to load an XML file, append data to it, then save it. The following bit of a code is a test routine which illustrates my problem : VBA Module : _________________________ "Option Base 1 Sub xmlDomManipulation() Dim xmlDoc As DOMDocument, root As IXMLDOMElement Set xmlDoc = New DOMDocument xmlDoc.async = False xmlDoc.Load (ThisWorkbook.Path & "\Bookstore.xml") Set root = xmlDoc.documentElement ReDim xmlYear(root.childNodes.Length) As IXMLDOMNode For i = 1 To root.childNodes.Length Set xmlYear(i) = root.childNodes.Item(1) ReDim xmlMonth(i, xmlYear(i).childNodes.Length) As IXMLDOMNode For j = 1 To xmlYear(i).childNodes.Length Set xmlMonth(i, j) = xmlYear(i).childNodes.Item(j) Next j Next i End Sub" XML File : ________________________ <?xml version="1.0"? <data <year y="2007" passed="1" <month m="1" <day d="01" ca="3497" pax="57"/ <day d="02" ca="5487" pax="73"/ <day d="03" ca="3256" pax="40"/ </month </year <year y="2008" passed="0" <month m="1" <day d="01" ca="3497" pax="57"/ <day d="02" ca="5487" pax="73"/ <day d="03" ca="3256" pax="40"/ </month </year </data When I check the results of this routine via locals windows, I see that xmlYear(i) is loaded correctly as an IXMLDOMNode, but xmlMonth(i, j) is set as nothing.... Any clues to the how and the why of this would be welcome... Cheers. |
Excel 2003 : Problem accessing childnodes in XMLDomElements
Well never mind I found the answer on my own...
Option Base 1 was the problem as it seems Excel starts item iteration at 0 and not 1. "mister tbo" wrote: Hello, Calling out for help... I've been searching and still clueless about this one... I'm trying to load an XML file, append data to it, then save it. The following bit of a code is a test routine which illustrates my problem : VBA Module : _________________________ "Option Base 1 Sub xmlDomManipulation() Dim xmlDoc As DOMDocument, root As IXMLDOMElement Set xmlDoc = New DOMDocument xmlDoc.async = False xmlDoc.Load (ThisWorkbook.Path & "\Bookstore.xml") Set root = xmlDoc.documentElement ReDim xmlYear(root.childNodes.Length) As IXMLDOMNode For i = 1 To root.childNodes.Length Set xmlYear(i) = root.childNodes.Item(1) ReDim xmlMonth(i, xmlYear(i).childNodes.Length) As IXMLDOMNode For j = 1 To xmlYear(i).childNodes.Length Set xmlMonth(i, j) = xmlYear(i).childNodes.Item(j) Next j Next i End Sub" XML File : ________________________ <?xml version="1.0"? <data <year y="2007" passed="1" <month m="1" <day d="01" ca="3497" pax="57"/ <day d="02" ca="5487" pax="73"/ <day d="03" ca="3256" pax="40"/ </month </year <year y="2008" passed="0" <month m="1" <day d="01" ca="3497" pax="57"/ <day d="02" ca="5487" pax="73"/ <day d="03" ca="3256" pax="40"/ </month </year </data When I check the results of this routine via locals windows, I see that xmlYear(i) is loaded correctly as an IXMLDOMNode, but xmlMonth(i, j) is set as nothing.... Any clues to the how and the why of this would be welcome... Cheers. |
All times are GMT +1. The time now is 04:14 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com