<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Reading XML Files in VBA</title>
	<atom:link href="http://www.dailydoseofexcel.com/archives/2009/06/16/reading-xml-files-in-vba/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dailydoseofexcel.com/archives/2009/06/16/reading-xml-files-in-vba/</link>
	<description>Daily posts of Excel tips…and other stuff</description>
	<lastBuildDate>Thu, 09 Feb 2012 23:42:03 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: david fischer</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/06/16/reading-xml-files-in-vba/#comment-61932</link>
		<dc:creator>david fischer</dc:creator>
		<pubDate>Fri, 08 Apr 2011 10:49:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=2591#comment-61932</guid>
		<description>&lt;p&gt;If you want to pull in an XML Database you could also try using an &lt;a href=&quot;//www.liquid-technologies.com/XML-Editor.aspx&quot;&quot; rel=&quot;nofollow&quot;&gt;XML Editor&lt;/a&gt;&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>If you want to pull in an XML Database you could also try using an <a href="//www.liquid-technologies.com/XML-Editor.aspx"" rel="nofollow">XML Editor</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nigel</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/06/16/reading-xml-files-in-vba/#comment-52694</link>
		<dc:creator>Nigel</dc:creator>
		<pubDate>Fri, 15 Oct 2010 17:11:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=2591#comment-52694</guid>
		<description>&lt;p&gt;Interesting stuff… &lt;/p&gt;

&lt;p&gt;No-one uses the inbuilt parsing functions of Microsoft’s XML document objects if they can avoid it: go find a PERL or a Python developer and pay them some money. Or buy them beer, they don’t get out much.&lt;/p&gt;

&lt;p&gt;That being said, we do still need to do this for ourselves from time to time, and I have some VBA lying around to do it. The problem is posting this stuff: Blogspot has issues with source code in general, XML in particular, and anything containing ‘&gt;’ is going to be a major headache when the material is cleaned up for (say) RSS readers.&lt;/p&gt;

&lt;p&gt;Let’s see how your custom &lt;code&gt; tags cope with this…&lt;/p&gt;

&lt;div style=&quot;overflow: auto; white-space: nowrap;&quot; class=&quot;codecolorer-container vb default&quot;&gt;&lt;div style=&quot;white-space: nowrap;&quot; class=&quot;vb codecolorer&quot;&gt;&lt;span class=&quot;co1&quot;&gt;&#039;&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039; Sample Input file:&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039;&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039; &#160;&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot; ?&gt;&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039; &#160;&lt;FUND_SETUP User=&quot;Heffernan&quot; DateStamp=&quot;14/09/2010 16:20:29&quot;&gt;&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039; &#160; &#160; &#160; &lt;FUND ID=&quot;FTSE_TRACKER_2007_GBP&quot;&gt;&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039; &#160; &#160; &#160; &#160; &#160; &lt;Ref_Index&gt;FTSE&lt;/Ref_Index&gt;&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039; &#160; &#160; &#160; &#160; &#160; &lt;Weighting&gt;100&lt;/Weighting&gt;&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039; &#160; &#160; &#160; &#160; &#160; &lt;Currency&gt;GBP&lt;/Currency&gt;&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039; &#160; &#160; &#160; &lt;/FUND&gt;&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039; &#160; &#160; &#160; &lt;FUND ID=&quot;CAC40_NY_QUANTO&quot;&gt;&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039; &#160; &#160; &#160; &#160; &#160; &lt;Ref_Index&gt;CAC40&lt;/Ref_Index&gt;&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039; &#160; &#160; &#160; &#160; &#160; &lt;Weighting&gt;40.6221038366675&lt;/Weighting&gt;&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039; &#160; &#160; &#160; &#160; &#160; &lt;Currency&gt;USD&lt;/Currency&gt;&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039; &#160; &#160; &#160; &lt;/FUND&gt;&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039; &#160; &lt;FUND_SETUP&gt;&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039;&lt;br&gt;
&lt;/span&gt;&#039;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;What we have here (if it’s loaded intellibly) is code to export and reload a very, very simple table: columns and rows, no nested data structure at all. &lt;/p&gt;

&lt;p&gt;Even this requires careful wrapping: if you’re lucky, you’ll get away with assuming that your XML-to-Excel parser doesn’t need to be told to look for a root element called FUND_SETUP (all XML files have a root element and I’m told that MS XMLDocument6 never fails to parse to parse it out and read the name) and you don’t need to look for the first-level element name as you get this for free in the ChildNodes collection…&lt;/p&gt;

&lt;p&gt;I believe the guy who told me that. But I can see why Python programmers don’t get out much, and I now know why nobody ever buys them beer. Me, I specify the root element, and I specify the names of the elements I want to import.&lt;/p&gt;

&lt;p&gt;This code’s taken from a ‘relation’ object: a class that wraps an array and allows us to refer to the rows and columns by name - so what you’ll see in the code sample below is an array (m_arrData), a dictionary of column names (m_dictCols) and a dictionary that acts as a row index (m_dictRows).&lt;/p&gt;

&lt;p&gt;What you’ll also see is that there’s a lot of work in a very simple data structure: it’s not just the overhead in all the data-cleaning, no-one’s ever managed to code up an XML import-export library that is truly ‘generic’, even for plain-vanilla relational data.&lt;/p&gt;

&lt;div style=&quot;overflow: auto; white-space: nowrap;&quot; class=&quot;codecolorer-container vb default&quot;&gt;&lt;div style=&quot;white-space: nowrap;&quot; class=&quot;vb codecolorer&quot;&gt;&lt;span class=&quot;co1&quot;&gt;&#039;&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039;&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039;&lt;br&gt;
&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;Public&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Sub&lt;/span&gt; LoadFromXML(objXMLdocument6 &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; MSXML2.DOMDocument60, _&lt;br&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Optional&lt;/span&gt; IndexColumnName &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;String&lt;/span&gt; = &lt;span class=&quot;st0&quot;&gt;&quot;&quot;&lt;/span&gt;, _&lt;br&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Optional&lt;/span&gt; RootTag &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;String&lt;/span&gt; = &lt;span class=&quot;st0&quot;&gt;&quot;&quot;&lt;/span&gt;, _&lt;br&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Optional&lt;/span&gt; RowTag &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;String&lt;/span&gt; = &lt;span class=&quot;st0&quot;&gt;&quot;&quot;&lt;/span&gt;, _&lt;br&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Optional&lt;/span&gt; bIgnoreRowAttributes &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Boolean&lt;/span&gt; = &lt;span class=&quot;kw1&quot;&gt;True&lt;/span&gt;, _&lt;br&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Optional&lt;/span&gt; bUseFirstRowFormat &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Boolean&lt;/span&gt; = &lt;span class=&quot;kw1&quot;&gt;True&lt;/span&gt;)&lt;br&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &lt;br&gt;
&#160;&lt;span class=&quot;kw1&quot;&gt;On&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Error&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Resume&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Next&lt;/span&gt;&lt;br&gt;
&#160;&lt;br&gt;
&lt;span class=&quot;co1&quot;&gt;&#039; This method will load tabular data from an XML file&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039; It is sensitive to file format, and will not accept all valid XML data:&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039; files: it expects that the XML file will represent simple tabular data&lt;br&gt;
&lt;/span&gt;&lt;br&gt;
&lt;span class=&quot;co1&quot;&gt;&#039; Optional RootTag As String = &quot;&quot;&lt;br&gt;
&lt;/span&gt; &lt;span class=&quot;co1&quot;&gt;&#039; Optional, identifies the parent node for the data table.&lt;br&gt;
&lt;/span&gt; &lt;span class=&quot;co1&quot;&gt;&#039; By default, the root node of the XML document will be used&lt;br&gt;
&lt;/span&gt; &lt;br&gt;
&lt;span class=&quot;co1&quot;&gt;&#039; Optional &#160;RowTag As String = &quot;&quot;&lt;br&gt;
&lt;/span&gt; &lt;span class=&quot;co1&quot;&gt;&#039; Optional, identifies the nodes or entities that we will use as rows in this relation&lt;br&gt;
&lt;/span&gt; &lt;span class=&quot;co1&quot;&gt;&#039; By default, all child nodes of the root entity will be loaded as rows&lt;br&gt;
&lt;/span&gt; &lt;br&gt;
&lt;span class=&quot;co1&quot;&gt;&#039; Optional &#160;IndexColumnName As String = &quot;&quot;&lt;br&gt;
&lt;/span&gt; &lt;span class=&quot;co1&quot;&gt;&#039; Optional, identifies the data &#039;column&#039; we will use as the unique row identifier&lt;br&gt;
&lt;/span&gt; &lt;span class=&quot;co1&quot;&gt;&#039; By default, the first attribute or the name of the first child node of the row entity will be used&lt;br&gt;
&lt;/span&gt; &lt;br&gt;
&lt;span class=&quot;co1&quot;&gt;&#039; Optional &#160;bIgnoreRowAttributes As Boolean&lt;br&gt;
&lt;/span&gt; &lt;span class=&quot;co1&quot;&gt;&#039; Read the child nodes only, ignoring the attributes of the entities that define each row&lt;br&gt;
&lt;/span&gt; &lt;br&gt;
&lt;span class=&quot;co1&quot;&gt;&#039; Optional &#160;bUseFirstRowFormat As Boolean&lt;br&gt;
&lt;/span&gt; &#160;&lt;span class=&quot;co1&quot;&gt;&#039;Do not scan the entire document to determine the column list&lt;br&gt;
&lt;/span&gt;&lt;br&gt;
&lt;span class=&quot;co1&quot;&gt;&#039; Duplicated Row ID&#039;s will be excluded from the final result: we&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039; only retain the row with the first occurrence of a given row ID&lt;br&gt;
&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
&lt;span class=&quot;co1&quot;&gt;&#039; Sample usage:&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039;&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039; &#160; &#160;Dim objXMLdocument6 As MSXML2.DOMDocument60&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039; &#160; &#160;Set objXMLdocument6 = New MSXML2.DOMDocument60&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039; &#160; &#160;objXMLdocument6.Load &quot;C:TempFund_setup.xml&quot;&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039;&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039; &#160; &#160;Dim relFund_Setup As clsRelation&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039; &#160; &#160;Set relFund_Setup = New clsRelation&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039; &#160; &#160;relETF_Setup.LoadFromXML objXMLdocument6, &quot;ID&quot;, &quot;FUND_SETUP&quot;, &quot;FUND&quot;, False, True&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039;&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039; Sample Input file:&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039;&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039; &#160;&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot; ?&gt;&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039; &#160;&lt;FUND_SETUP User=&quot;Heffernan&quot; DateStamp=&quot;14/09/2010 16:20:29&quot;&gt;&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039; &#160; &#160; &#160; &lt;FUND ID=&quot;FTSE_TRACKER_2007_GBP&quot;&gt;&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039; &#160; &#160; &#160; &#160; &#160; &lt;Ref_Index&gt;FTSE&lt;/Ref_Index&gt;&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039; &#160; &#160; &#160; &#160; &#160; &lt;Weighting&gt;100&lt;/Weighting&gt;&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039; &#160; &#160; &#160; &#160; &#160; &lt;Currency&gt;GBP&lt;/Currency&gt;&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039; &#160; &#160; &#160; &lt;/FUND&gt;&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039; &#160; &#160; &#160; &lt;FUND ID=&quot;CAC40_NY_QUANTO&quot;&gt;&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039; &#160; &#160; &#160; &#160; &#160; &lt;Ref_Index&gt;CAC40&lt;/Ref_Index&gt;&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039; &#160; &#160; &#160; &#160; &#160; &lt;Weighting&gt;40.6221038366675&lt;/Weighting&gt;&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039; &#160; &#160; &#160; &#160; &#160; &lt;Currency&gt;USD&lt;/Currency&gt;&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039; &#160; &#160; &#160; &lt;/FUND&gt;&lt;br&gt;
&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;&#039; &#160; &lt;FUND_SETUP&gt;&lt;br&gt;
&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; oXMLattribute &#160; &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; MSXML2.IXMLDOMAttribute&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; oXMLnode &#160; &#160; &#160; &#160;&lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; MSXML2.IXMLDOMNode&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; oXMLnodeRoot &#160; &#160;&lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; MSXML2.IXMLDOMNode&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; oXMLnodeChild &#160; &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; MSXML2.IXMLDOMNode&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; oXMLnodeList &#160; &#160;&lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; MSXML2.IXMLDOMNodeList&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; varData &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Variant&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; iRowCount &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Integer&lt;/span&gt;&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; iColCount &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Integer&lt;/span&gt;&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; iRow &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Integer&lt;/span&gt;&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; iCol &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Integer&lt;/span&gt;&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; i &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Integer&lt;/span&gt;&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; j &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Integer&lt;/span&gt;&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; strColName &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;String&lt;/span&gt;&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; strRowID &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;String&lt;/span&gt;&lt;br&gt;
&#160;&lt;br&gt;
&lt;br&gt;
&#160; &#160; &lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; RootTag = &lt;span class=&quot;st0&quot;&gt;&quot;&quot;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Set&lt;/span&gt; oXMLnodeRoot = &lt;span class=&quot;kw1&quot;&gt;Nothing&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Set&lt;/span&gt; oXMLnodeRoot = objXMLdocument6.selectNodes(&lt;span class=&quot;st0&quot;&gt;&quot;/*&quot;&lt;/span&gt;).Item(0)&lt;br&gt;
&#160; &#160; &#160; &#160; RootTag = oXMLnodeRoot.baseName&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Else&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Set&lt;/span&gt; oXMLnodeList = objXMLdocument6.getElementsByTagName(RootTag)&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Set&lt;/span&gt; oXMLnodeRoot = oXMLnodeList.NextNode&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt;&lt;br&gt;
&#160; &#160; &lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; oXMLnodeRoot &lt;span class=&quot;kw1&quot;&gt;Is&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Nothing&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;GoTo&lt;/span&gt; ExitSub&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt;&lt;br&gt;
&#160; &#160; &lt;br&gt;
&#160; &#160; &lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;For&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Each&lt;/span&gt; oXMLattribute &lt;span class=&quot;kw1&quot;&gt;In&lt;/span&gt; oXMLnodeRoot.Attributes&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; Me.Attributes.Exists(oXMLattribute.Name) &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; &#160; &#160; Me.Attributes(oXMLattribute.Name) = oXMLattribute.Value&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Else&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; &#160; &#160; Me.Attributes.Add oXMLattribute.Name, oXMLattribute.Value&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Next&lt;/span&gt; &lt;span class=&quot;co1&quot;&gt;&#039; oXMLattribute&lt;br&gt;
&lt;/span&gt; &#160; &#160;&lt;br&gt;
&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Not&lt;/span&gt; oXMLnodeRoot.hasChildNodes &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;GoTo&lt;/span&gt; ExitSub&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt;&lt;br&gt;
&#160; &#160; &lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Set&lt;/span&gt; oXMLnodeList = &lt;span class=&quot;kw1&quot;&gt;Nothing&lt;/span&gt;&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; RowTag = &lt;span class=&quot;st0&quot;&gt;&quot;&quot;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Set&lt;/span&gt; oXMLnodeList = objXMLdocument6.selectNodes(&lt;span class=&quot;st0&quot;&gt;&quot;./*/*&quot;&lt;/span&gt;)&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Else&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Set&lt;/span&gt; oXMLnodeList = objXMLdocument6.getElementsByTagName(RowTag)&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt;&lt;br&gt;
&#160; &#160; &lt;br&gt;
&#160; &#160; &lt;br&gt;
&#160; &#160; iRowCount = oXMLnodeList.Length&lt;br&gt;
&#160; &#160; &lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; iRowCount = 0 &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;GoTo&lt;/span&gt; ExitSub&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &lt;br&gt;
&#160; &#160; &lt;span class=&quot;co1&quot;&gt;&#039; Two passes through the document:&lt;br&gt;
&lt;/span&gt; &#160; &#160;&lt;span class=&quot;co1&quot;&gt;&#039; &#160; First pass, get the dimensions and column names;&lt;br&gt;
&lt;/span&gt; &#160; &#160;&lt;span class=&quot;co1&quot;&gt;&#039; &#160; (this pass can be specified as &#039;use Row 1 only&#039;)&lt;br&gt;
&lt;/span&gt; &#160; &#160;&lt;span class=&quot;co1&quot;&gt;&#039; &#160; Second pass, populate the relation&#039;s data array.&lt;br&gt;
&lt;/span&gt; &#160; &#160;&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Set&lt;/span&gt; m_dictCols = &lt;span class=&quot;kw1&quot;&gt;Nothing&lt;/span&gt;&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Set&lt;/span&gt; m_dictCols = &lt;span class=&quot;kw1&quot;&gt;New&lt;/span&gt; Scripting.Dictionary&lt;br&gt;
&#160; &#160; &lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; IndexColumnName &lt;&gt; &lt;span class=&quot;st0&quot;&gt;&quot;&quot;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; m_dictCols.Add IndexColumnName, 1&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt;&lt;br&gt;
&#160; &#160; &lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;For&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Each&lt;/span&gt; oXMLnode &lt;span class=&quot;kw1&quot;&gt;In&lt;/span&gt; oXMLnodeList&lt;br&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; bIgnoreRowAttributes = &lt;span class=&quot;kw1&quot;&gt;False&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;For&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Each&lt;/span&gt; oXMLattribute &lt;span class=&quot;kw1&quot;&gt;In&lt;/span&gt; oXMLnode.Attributes&lt;br&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Not&lt;/span&gt; m_dictCols.Exists(oXMLattribute.Name) &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; m_dictCols.Add oXMLattribute.Name, m_dictCols.Count + 1&lt;br&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Next&lt;/span&gt; oXMLattribute&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;For&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Each&lt;/span&gt; oXMLnodeChild &lt;span class=&quot;kw1&quot;&gt;In&lt;/span&gt; oXMLnode.childNodes&lt;br&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &lt;br&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Not&lt;/span&gt; m_dictCols.Exists(oXMLnodeChild.nodeName) &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; m_dictCols.Add oXMLnodeChild.nodeName, m_dictCols.Count + 1&lt;br&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Next&lt;/span&gt; oXMLnodeChild&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; bUseFirstRowFormat &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Exit&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;For&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Next&lt;/span&gt;&lt;br&gt;
&#160; &#160; &lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; m_dictCols.Count = 0 &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;GoTo&lt;/span&gt; ExitSub&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt;&lt;br&gt;
&#160; &#160; &lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; IndexColumnName = &lt;span class=&quot;st0&quot;&gt;&quot;&quot;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; IndexColumnName = m_dictCols.Keys(0)&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &lt;br&gt;
&#160;&lt;br&gt;
&lt;br&gt;
&#160; &#160; iColCount = m_dictCols.Count&lt;br&gt;
&#160; &#160; &lt;br&gt;
&#160; &#160; &lt;br&gt;
&#160; &#160; &lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Set&lt;/span&gt; m_dictRows = &lt;span class=&quot;kw1&quot;&gt;New&lt;/span&gt; Scripting.Dictionary&lt;br&gt;
&#160; &#160; iRow = 0&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;ReDim&lt;/span&gt; varData(1 &lt;span class=&quot;kw1&quot;&gt;To&lt;/span&gt; iRowCount, 1 &lt;span class=&quot;kw1&quot;&gt;To&lt;/span&gt; iColCount)&lt;br&gt;
&#160;&lt;br&gt;
&#160; &#160; &lt;br&gt;
&#160; &#160; &#160;&lt;span class=&quot;kw1&quot;&gt;For&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Each&lt;/span&gt; oXMLnode &lt;span class=&quot;kw1&quot;&gt;In&lt;/span&gt; oXMLnodeList&lt;br&gt;
&#160; &#160; &#160;iRow = iRow + 1&lt;br&gt;
&#160; &#160; &#160; &#160; &#160; &#160;&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; bIgnoreRowAttributes = &lt;span class=&quot;kw1&quot;&gt;False&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;For&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Each&lt;/span&gt; oXMLattribute &lt;span class=&quot;kw1&quot;&gt;In&lt;/span&gt; oXMLnode.Attributes&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;br&gt;
&#160; &#160; &#160; &#160; &#160; &#160; strColName = &lt;span class=&quot;st0&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; &#160; &#160; strColName = oXMLattribute.Name&lt;br&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &lt;br&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; m_dictCols.Exists(strColName) &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; iCol = m_dictCols(strColName)&lt;br&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; varData(iRow, iCol) = oXMLattribute.Value&lt;br&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Next&lt;/span&gt; oXMLattribute&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;For&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Each&lt;/span&gt; oXMLnodeChild &lt;span class=&quot;kw1&quot;&gt;In&lt;/span&gt; oXMLnode.childNodes&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;br&gt;</description>
		<content:encoded><![CDATA[<p>Interesting stuff… </p>
<p>No-one uses the inbuilt parsing functions of Microsoft’s XML document objects if they can avoid it: go find a PERL or a Python developer and pay them some money. Or buy them beer, they don’t get out much.</p>
<p>That being said, we do still need to do this for ourselves from time to time, and I have some VBA lying around to do it. The problem is posting this stuff: Blogspot has issues with source code in general, XML in particular, and anything containing ‘&gt;’ is going to be a major headache when the material is cleaned up for (say) RSS readers.</p>
<p>Let’s see how your custom &lt;code&gt; tags cope with this…</p>
<div style="overflow: auto; white-space: nowrap;" class="codecolorer-container vb default">
<div style="white-space: nowrap;" class="vb codecolorer"><span class="co1">&#8216;<br />
</span><span class="co1">&#8216; Sample Input file:<br />
</span><span class="co1">&#8216;<br />
</span><span class="co1">&#8216; &nbsp;&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;UTF-8&#8243; standalone=&#8221;yes&#8221; ?&gt;<br />
</span><span class="co1">&#8216; &nbsp;&lt;FUND_SETUP User=&#8221;Heffernan&#8221; DateStamp=&#8221;14/09/2010 16:20:29&#8243;&gt;<br />
</span><span class="co1">&#8216; &nbsp; &nbsp; &nbsp; &lt;FUND ID=&#8221;FTSE_TRACKER_2007_GBP&#8221;&gt;<br />
</span><span class="co1">&#8216; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;Ref_Index&gt;FTSE&lt;/Ref_Index&gt;<br />
</span><span class="co1">&#8216; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;Weighting&gt;100&lt;/Weighting&gt;<br />
</span><span class="co1">&#8216; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;Currency&gt;GBP&lt;/Currency&gt;<br />
</span><span class="co1">&#8216; &nbsp; &nbsp; &nbsp; &lt;/FUND&gt;<br />
</span><span class="co1">&#8216; &nbsp; &nbsp; &nbsp; &lt;FUND ID=&#8221;CAC40_NY_QUANTO&#8221;&gt;<br />
</span><span class="co1">&#8216; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;Ref_Index&gt;CAC40&lt;/Ref_Index&gt;<br />
</span><span class="co1">&#8216; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;Weighting&gt;40.6221038366675&lt;/Weighting&gt;<br />
</span><span class="co1">&#8216; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;Currency&gt;USD&lt;/Currency&gt;<br />
</span><span class="co1">&#8216; &nbsp; &nbsp; &nbsp; &lt;/FUND&gt;<br />
</span><span class="co1">&#8216; &nbsp; &lt;FUND_SETUP&gt;<br />
</span><span class="co1">&#8216;<br />
</span>&#8216;</div>
</div>
<p>What we have here (if it’s loaded intellibly) is code to export and reload a very, very simple table: columns and rows, no nested data structure at all. </p>
<p>Even this requires careful wrapping: if you’re lucky, you’ll get away with assuming that your XML-to-Excel parser doesn’t need to be told to look for a root element called FUND_SETUP (all XML files have a root element and I’m told that MS XMLDocument6 never fails to parse to parse it out and read the name) and you don’t need to look for the first-level element name as you get this for free in the ChildNodes collection…</p>
<p>I believe the guy who told me that. But I can see why Python programmers don’t get out much, and I now know why nobody ever buys them beer. Me, I specify the root element, and I specify the names of the elements I want to import.</p>
<p>This code’s taken from a ‘relation’ object: a class that wraps an array and allows us to refer to the rows and columns by name &#8211; so what you’ll see in the code sample below is an array (m_arrData), a dictionary of column names (m_dictCols) and a dictionary that acts as a row index (m_dictRows).</p>
<p>What you’ll also see is that there’s a lot of work in a very simple data structure: it’s not just the overhead in all the data-cleaning, no-one’s ever managed to code up an XML import-export library that is truly ‘generic’, even for plain-vanilla relational data.</p>
<div style="overflow: auto; white-space: nowrap;" class="codecolorer-container vb default">
<div style="white-space: nowrap;" class="vb codecolorer"><span class="co1">&#8216;<br />
</span><span class="co1">&#8216;<br />
</span><span class="co1">&#8216;<br />
</span></p>
<p><span class="kw1">Public</span> <span class="kw1">Sub</span> LoadFromXML(objXMLdocument6 <span class="kw1">As</span> MSXML2.DOMDocument60, _<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">Optional</span> IndexColumnName <span class="kw1">As</span> <span class="kw1">String</span> = <span class="st0">&#8220;&#8221;</span>, _<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">Optional</span> RootTag <span class="kw1">As</span> <span class="kw1">String</span> = <span class="st0">&#8220;&#8221;</span>, _<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">Optional</span> RowTag <span class="kw1">As</span> <span class="kw1">String</span> = <span class="st0">&#8220;&#8221;</span>, _<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">Optional</span> bIgnoreRowAttributes <span class="kw1">As</span> <span class="kw1">Boolean</span> = <span class="kw1">True</span>, _<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">Optional</span> bUseFirstRowFormat <span class="kw1">As</span> <span class="kw1">Boolean</span> = <span class="kw1">True</span>)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp;<span class="kw1">On</span> <span class="kw1">Error</span> <span class="kw1">Resume</span> <span class="kw1">Next</span><br />
&nbsp;<br />
<span class="co1">&#8216; This method will load tabular data from an XML file<br />
</span><span class="co1">&#8216; It is sensitive to file format, and will not accept all valid XML data:<br />
</span><span class="co1">&#8216; files: it expects that the XML file will represent simple tabular data<br />
</span><br />
<span class="co1">&#8216; Optional RootTag As String = &#8220;&#8221;<br />
</span> <span class="co1">&#8216; Optional, identifies the parent node for the data table.<br />
</span> <span class="co1">&#8216; By default, the root node of the XML document will be used<br />
</span> <br />
<span class="co1">&#8216; Optional &nbsp;RowTag As String = &#8220;&#8221;<br />
</span> <span class="co1">&#8216; Optional, identifies the nodes or entities that we will use as rows in this relation<br />
</span> <span class="co1">&#8216; By default, all child nodes of the root entity will be loaded as rows<br />
</span> <br />
<span class="co1">&#8216; Optional &nbsp;IndexColumnName As String = &#8220;&#8221;<br />
</span> <span class="co1">&#8216; Optional, identifies the data &#8216;column&#8217; we will use as the unique row identifier<br />
</span> <span class="co1">&#8216; By default, the first attribute or the name of the first child node of the row entity will be used<br />
</span> <br />
<span class="co1">&#8216; Optional &nbsp;bIgnoreRowAttributes As Boolean<br />
</span> <span class="co1">&#8216; Read the child nodes only, ignoring the attributes of the entities that define each row<br />
</span> <br />
<span class="co1">&#8216; Optional &nbsp;bUseFirstRowFormat As Boolean<br />
</span> &nbsp;<span class="co1">&#8216;Do not scan the entire document to determine the column list<br />
</span><br />
<span class="co1">&#8216; Duplicated Row ID&#8217;s will be excluded from the final result: we<br />
</span><span class="co1">&#8216; only retain the row with the first occurrence of a given row ID<br />
</span></p>
<p><span class="co1">&#8216; Sample usage:<br />
</span><span class="co1">&#8216;<br />
</span><span class="co1">&#8216; &nbsp; &nbsp;Dim objXMLdocument6 As MSXML2.DOMDocument60<br />
</span><span class="co1">&#8216; &nbsp; &nbsp;Set objXMLdocument6 = New MSXML2.DOMDocument60<br />
</span><span class="co1">&#8216; &nbsp; &nbsp;objXMLdocument6.Load &#8220;C:TempFund_setup.xml&#8221;<br />
</span><span class="co1">&#8216;<br />
</span><span class="co1">&#8216; &nbsp; &nbsp;Dim relFund_Setup As clsRelation<br />
</span><span class="co1">&#8216; &nbsp; &nbsp;Set relFund_Setup = New clsRelation<br />
</span><span class="co1">&#8216; &nbsp; &nbsp;relETF_Setup.LoadFromXML objXMLdocument6, &#8220;ID&#8221;, &#8220;FUND_SETUP&#8221;, &#8220;FUND&#8221;, False, True<br />
</span><span class="co1">&#8216;<br />
</span><span class="co1">&#8216; Sample Input file:<br />
</span><span class="co1">&#8216;<br />
</span><span class="co1">&#8216; &nbsp;&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;UTF-8&#8243; standalone=&#8221;yes&#8221; ?&gt;<br />
</span><span class="co1">&#8216; &nbsp;&lt;FUND_SETUP User=&#8221;Heffernan&#8221; DateStamp=&#8221;14/09/2010 16:20:29&#8243;&gt;<br />
</span><span class="co1">&#8216; &nbsp; &nbsp; &nbsp; &lt;FUND ID=&#8221;FTSE_TRACKER_2007_GBP&#8221;&gt;<br />
</span><span class="co1">&#8216; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;Ref_Index&gt;FTSE&lt;/Ref_Index&gt;<br />
</span><span class="co1">&#8216; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;Weighting&gt;100&lt;/Weighting&gt;<br />
</span><span class="co1">&#8216; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;Currency&gt;GBP&lt;/Currency&gt;<br />
</span><span class="co1">&#8216; &nbsp; &nbsp; &nbsp; &lt;/FUND&gt;<br />
</span><span class="co1">&#8216; &nbsp; &nbsp; &nbsp; &lt;FUND ID=&#8221;CAC40_NY_QUANTO&#8221;&gt;<br />
</span><span class="co1">&#8216; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;Ref_Index&gt;CAC40&lt;/Ref_Index&gt;<br />
</span><span class="co1">&#8216; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;Weighting&gt;40.6221038366675&lt;/Weighting&gt;<br />
</span><span class="co1">&#8216; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;Currency&gt;USD&lt;/Currency&gt;<br />
</span><span class="co1">&#8216; &nbsp; &nbsp; &nbsp; &lt;/FUND&gt;<br />
</span><span class="co1">&#8216; &nbsp; &lt;FUND_SETUP&gt;<br />
</span></p>
<p><span class="kw1">Dim</span> oXMLattribute &nbsp; <span class="kw1">As</span> MSXML2.IXMLDOMAttribute<br />
<span class="kw1">Dim</span> oXMLnode &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">As</span> MSXML2.IXMLDOMNode<br />
<span class="kw1">Dim</span> oXMLnodeRoot &nbsp; &nbsp;<span class="kw1">As</span> MSXML2.IXMLDOMNode<br />
<span class="kw1">Dim</span> oXMLnodeChild &nbsp; <span class="kw1">As</span> MSXML2.IXMLDOMNode<br />
<span class="kw1">Dim</span> oXMLnodeList &nbsp; &nbsp;<span class="kw1">As</span> MSXML2.IXMLDOMNodeList</p>
<p>
<span class="kw1">Dim</span> varData <span class="kw1">As</span> <span class="kw1">Variant</span></p>
<p><span class="kw1">Dim</span> iRowCount <span class="kw1">As</span> <span class="kw1">Integer</span><br />
<span class="kw1">Dim</span> iColCount <span class="kw1">As</span> <span class="kw1">Integer</span><br />
<span class="kw1">Dim</span> iRow <span class="kw1">As</span> <span class="kw1">Integer</span><br />
<span class="kw1">Dim</span> iCol <span class="kw1">As</span> <span class="kw1">Integer</span><br />
<span class="kw1">Dim</span> i <span class="kw1">As</span> <span class="kw1">Integer</span><br />
<span class="kw1">Dim</span> j <span class="kw1">As</span> <span class="kw1">Integer</span><br />
<span class="kw1">Dim</span> strColName <span class="kw1">As</span> <span class="kw1">String</span><br />
<span class="kw1">Dim</span> strRowID <span class="kw1">As</span> <span class="kw1">String</span><br />
&nbsp;</p>
<p>&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw1">If</span> RootTag = <span class="st0">&#8220;&#8221;</span> <span class="kw1">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">Set</span> oXMLnodeRoot = <span class="kw1">Nothing</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">Set</span> oXMLnodeRoot = objXMLdocument6.selectNodes(<span class="st0">&#8220;/*&#8221;</span>).Item(0)<br />
&nbsp; &nbsp; &nbsp; &nbsp; RootTag = oXMLnodeRoot.baseName<br />
&nbsp; &nbsp; <span class="kw1">Else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">Set</span> oXMLnodeList = objXMLdocument6.getElementsByTagName(RootTag)<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">Set</span> oXMLnodeRoot = oXMLnodeList.NextNode<br />
&nbsp; &nbsp; <span class="kw1">End</span> <span class="kw1">If</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw1">If</span> oXMLnodeRoot <span class="kw1">Is</span> <span class="kw1">Nothing</span> <span class="kw1">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">GoTo</span> ExitSub<br />
&nbsp; &nbsp; <span class="kw1">End</span> <span class="kw1">If</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw1">For</span> <span class="kw1">Each</span> oXMLattribute <span class="kw1">In</span> oXMLnodeRoot.Attributes<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">If</span> Me.Attributes.Exists(oXMLattribute.Name) <span class="kw1">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Me.Attributes(oXMLattribute.Name) = oXMLattribute.Value<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">Else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Me.Attributes.Add oXMLattribute.Name, oXMLattribute.Value<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">End</span> <span class="kw1">If</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw1">Next</span> <span class="co1">&#8216; oXMLattribute<br />
</span> &nbsp; &nbsp;</p>
<p>&nbsp; &nbsp; <span class="kw1">If</span> <span class="kw1">Not</span> oXMLnodeRoot.hasChildNodes <span class="kw1">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">GoTo</span> ExitSub<br />
&nbsp; &nbsp; <span class="kw1">End</span> <span class="kw1">If</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw1">Set</span> oXMLnodeList = <span class="kw1">Nothing</span><br />
&nbsp; &nbsp; <span class="kw1">If</span> RowTag = <span class="st0">&#8220;&#8221;</span> <span class="kw1">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">Set</span> oXMLnodeList = objXMLdocument6.selectNodes(<span class="st0">&#8220;./*/*&#8221;</span>)<br />
&nbsp; &nbsp; <span class="kw1">Else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">Set</span> oXMLnodeList = objXMLdocument6.getElementsByTagName(RowTag)<br />
&nbsp; &nbsp; <span class="kw1">End</span> <span class="kw1">If</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; iRowCount = oXMLnodeList.Length<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw1">If</span> iRowCount = 0 <span class="kw1">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">GoTo</span> ExitSub<br />
&nbsp; &nbsp; <span class="kw1">End</span> <span class="kw1">If</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="co1">&#8216; Two passes through the document:<br />
</span> &nbsp; &nbsp;<span class="co1">&#8216; &nbsp; First pass, get the dimensions and column names;<br />
</span> &nbsp; &nbsp;<span class="co1">&#8216; &nbsp; (this pass can be specified as &#8216;use Row 1 only&#8217;)<br />
</span> &nbsp; &nbsp;<span class="co1">&#8216; &nbsp; Second pass, populate the relation&#8217;s data array.<br />
</span> &nbsp; &nbsp;<br />
&nbsp; &nbsp; <span class="kw1">Set</span> m_dictCols = <span class="kw1">Nothing</span><br />
&nbsp; &nbsp; <span class="kw1">Set</span> m_dictCols = <span class="kw1">New</span> Scripting.Dictionary<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw1">If</span> IndexColumnName &lt;&gt; <span class="st0">&#8220;&#8221;</span> <span class="kw1">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; m_dictCols.Add IndexColumnName, 1<br />
&nbsp; &nbsp; <span class="kw1">End</span> <span class="kw1">If</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw1">For</span> <span class="kw1">Each</span> oXMLnode <span class="kw1">In</span> oXMLnodeList<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">If</span> bIgnoreRowAttributes = <span class="kw1">False</span> <span class="kw1">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">For</span> <span class="kw1">Each</span> oXMLattribute <span class="kw1">In</span> oXMLnode.Attributes<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">If</span> <span class="kw1">Not</span> m_dictCols.Exists(oXMLattribute.Name) <span class="kw1">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_dictCols.Add oXMLattribute.Name, m_dictCols.Count + 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">End</span> <span class="kw1">If</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">Next</span> oXMLattribute<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">End</span> <span class="kw1">If</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">For</span> <span class="kw1">Each</span> oXMLnodeChild <span class="kw1">In</span> oXMLnode.childNodes<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">If</span> <span class="kw1">Not</span> m_dictCols.Exists(oXMLnodeChild.nodeName) <span class="kw1">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_dictCols.Add oXMLnodeChild.nodeName, m_dictCols.Count + 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">End</span> <span class="kw1">If</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">Next</span> oXMLnodeChild<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">If</span> bUseFirstRowFormat <span class="kw1">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">Exit</span> <span class="kw1">For</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">End</span> <span class="kw1">If</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw1">Next</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw1">If</span> m_dictCols.Count = 0 <span class="kw1">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">GoTo</span> ExitSub<br />
&nbsp; &nbsp; <span class="kw1">End</span> <span class="kw1">If</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw1">If</span> IndexColumnName = <span class="st0">&#8220;&#8221;</span> <span class="kw1">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; IndexColumnName = m_dictCols.Keys(0)<br />
&nbsp; &nbsp; <span class="kw1">End</span> <span class="kw1">If</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp;</p>
<p>&nbsp; &nbsp; iColCount = m_dictCols.Count<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw1">Set</span> m_dictRows = <span class="kw1">New</span> Scripting.Dictionary<br />
&nbsp; &nbsp; iRow = 0<br />
&nbsp; &nbsp; <span class="kw1">ReDim</span> varData(1 <span class="kw1">To</span> iRowCount, 1 <span class="kw1">To</span> iColCount)<br />
&nbsp;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp;<span class="kw1">For</span> <span class="kw1">Each</span> oXMLnode <span class="kw1">In</span> oXMLnodeList<br />
&nbsp; &nbsp; &nbsp;iRow = iRow + 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">If</span> bIgnoreRowAttributes = <span class="kw1">False</span> <span class="kw1">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">For</span> <span class="kw1">Each</span> oXMLattribute <span class="kw1">In</span> oXMLnode.Attributes<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strColName = <span class="st0">&#8220;&#8221;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strColName = oXMLattribute.Name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">If</span> m_dictCols.Exists(strColName) <span class="kw1">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; iCol = m_dictCols(strColName)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; varData(iRow, iCol) = oXMLattribute.Value<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">End</span> <span class="kw1">If</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">Next</span> oXMLattribute<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">End</span> <span class="kw1">If</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">For</span> <span class="kw1">Each</span> oXMLnodeChild <span class="kw1">In</span> oXMLnode.childNodes<br />
&nbsp; &nbsp; &nbsp; &nbsp; </div>
</div>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vikas</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/06/16/reading-xml-files-in-vba/#comment-52678</link>
		<dc:creator>Vikas</dc:creator>
		<pubDate>Fri, 15 Oct 2010 08:34:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=2591#comment-52678</guid>
		<description>&lt;p&gt;Thank you very much for your post regarding reading XML file .&lt;/p&gt;
&lt;p&gt;It is really usefull.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Thank you very much for your post regarding reading XML file .</p>
<p>It is really usefull.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bj</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/06/16/reading-xml-files-in-vba/#comment-44863</link>
		<dc:creator>bj</dc:creator>
		<pubDate>Fri, 26 Mar 2010 05:18:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=2591#comment-44863</guid>
		<description>&lt;p&gt;I even preceded it with &#039; that time and it still dissapeared. &lt;/p&gt;
&lt;p&gt;I&#039;ll take the front bracket off the  line and try again so please remember to put it back on. :)&lt;/p&gt;
&lt;p&gt;?xml version=&quot;1.0??&gt;&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I even preceded it with &#8216; that time and it still dissapeared. </p>
<p>I&#8217;ll take the front bracket off the  line and try again so please remember to put it back on. <img src='http://www.dailydoseofexcel.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>?xml version=&#8221;1.0??&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bj</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/06/16/reading-xml-files-in-vba/#comment-44862</link>
		<dc:creator>bj</dc:creator>
		<pubDate>Fri, 26 Mar 2010 05:16:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=2591#comment-44862</guid>
		<description>&lt;p&gt;Hmmm that was interesting... the xml code went into the html blackhole.&lt;/p&gt;
&lt;p&gt;Here it is again:&lt;/p&gt;
&lt;p&gt;&#039;&lt;br&gt;
&#039;&lt;br&gt;
&#039;&lt;br&gt;
&#039;&lt;br&gt;
&#039;&lt;br&gt;
&#039;&lt;br&gt;
&#039;&lt;br&gt;
&#039;&lt;br&gt;
&#039;&lt;br&gt;
&#039;&lt;br&gt;
&#039;&lt;br&gt;
&#039;&lt;br&gt;
&#039;&lt;br&gt;
&#039;&lt;br&gt;
&#039;&lt;br&gt;
&#039;&lt;br&gt;
&#039;&lt;br&gt;
&#039;&lt;br&gt;
&#039;&lt;br&gt;
&#039;&lt;br&gt;
&#039;&lt;br&gt;
&#039;&lt;br&gt;
&#039;&lt;br&gt;
&#039;&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Hmmm that was interesting&#8230; the xml code went into the html blackhole.</p>
<p>Here it is again:</p>
<p>&#8216;<br />
&#8216;<br />
&#8216;<br />
&#8216;<br />
&#8216;<br />
&#8216;<br />
&#8216;<br />
&#8216;<br />
&#8216;<br />
&#8216;<br />
&#8216;<br />
&#8216;<br />
&#8216;<br />
&#8216;<br />
&#8216;<br />
&#8216;<br />
&#8216;<br />
&#8216;<br />
&#8216;<br />
&#8216;<br />
&#8216;<br />
&#8216;<br />
&#8216;<br />
&#8216;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bj</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/06/16/reading-xml-files-in-vba/#comment-44861</link>
		<dc:creator>bj</dc:creator>
		<pubDate>Fri, 26 Mar 2010 05:14:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=2591#comment-44861</guid>
		<description>&lt;p&gt;Hi guys.&lt;/p&gt;
&lt;p&gt;I&#039;m not new to VBA but I am to XML and the use of inbuilt parsers.&lt;/p&gt;
&lt;p&gt;I am trying to parse an XML file but it is driving me nuts right now. I have an xml file, sampled as follows:&lt;/p&gt;
&lt;p&gt;So far I can get the highest level node titles but not the &quot;Categories&quot; which I need and the best, neatest, smallest lot of code I have so far, in a day of looking, trying and modifying is the following:&lt;/p&gt;
&lt;p&gt;Sub getWikiInfoViaXML()&lt;/p&gt;
&lt;p&gt;    Dim xmlDoc As New DOMDocument&lt;br&gt;
    Dim fileOK As Boolean&lt;br&gt;
    Dim myNode As IXMLDOMElement&lt;br&gt;
    Dim myCNode As IXMLDOMNode&lt;br&gt;
    Dim a As Integer&lt;/p&gt;
&lt;p&gt;    fileOK = xmlDoc.Load(&quot;FilePAthallPages.xml&quot;)&lt;/p&gt;
&lt;p&gt;    a = 2&lt;br&gt;
    If fileOK Then&lt;br&gt;
        With Sheets(&quot;Wiki Source Docs&quot;)&lt;br&gt;
            For Each myNode In xmlDoc.selectNodes(&quot;//page&quot;)&lt;br&gt;
                .Cells(a, 1) = myNode.getAttribute(&quot;title&quot;)&lt;br&gt;
                a = a + 1&lt;br&gt;
            Next myNode&lt;br&gt;
        End With&lt;br&gt;
    Else&lt;br&gt;
        MsgBox &quot;Unable to open the file selected&quot;&lt;br&gt;
    End If&lt;br&gt;
End Sub&lt;/p&gt;
&lt;p&gt;Any help would be appreciated.&lt;/p&gt;
&lt;p&gt;TIA.&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;BJ&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Hi guys.</p>
<p>I&#8217;m not new to VBA but I am to XML and the use of inbuilt parsers.</p>
<p>I am trying to parse an XML file but it is driving me nuts right now. I have an xml file, sampled as follows:</p>
<p>So far I can get the highest level node titles but not the &#8220;Categories&#8221; which I need and the best, neatest, smallest lot of code I have so far, in a day of looking, trying and modifying is the following:</p>
<p>Sub getWikiInfoViaXML()</p>
<p>    Dim xmlDoc As New DOMDocument<br />
    Dim fileOK As Boolean<br />
    Dim myNode As IXMLDOMElement<br />
    Dim myCNode As IXMLDOMNode<br />
    Dim a As Integer</p>
<p>    fileOK = xmlDoc.Load(&#8220;FilePAthallPages.xml&#8221;)</p>
<p>    a = 2<br />
    If fileOK Then<br />
        With Sheets(&#8220;Wiki Source Docs&#8221;)<br />
            For Each myNode In xmlDoc.selectNodes(&#8220;//page&#8221;)<br />
                .Cells(a, 1) = myNode.getAttribute(&#8220;title&#8221;)<br />
                a = a + 1<br />
            Next myNode<br />
        End With<br />
    Else<br />
        MsgBox &#8220;Unable to open the file selected&#8221;<br />
    End If<br />
End Sub</p>
<p>Any help would be appreciated.</p>
<p>TIA.</p>
<p>Cheers,</p>
<p>BJ</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jon Peltier</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/06/16/reading-xml-files-in-vba/#comment-39970</link>
		<dc:creator>Jon Peltier</dc:creator>
		<pubDate>Mon, 22 Jun 2009 01:46:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=2591#comment-39970</guid>
		<description>&lt;p&gt;I would have just said &quot;code like mine&quot;.&lt;/p&gt;
&lt;p&gt;I also thought I needed a variant for Split. I had to test it just now to check. No day is wasted if I learn something.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I would have just said &#8220;code like mine&#8221;.</p>
<p>I also thought I needed a variant for Split. I had to test it just now to check. No day is wasted if I learn something.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jeffrey weir</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/06/16/reading-xml-files-in-vba/#comment-39966</link>
		<dc:creator>jeffrey weir</dc:creator>
		<pubDate>Sun, 21 Jun 2009 01:36:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=2591#comment-39966</guid>
		<description>&lt;p&gt;keepITCool: on a site dedicated to teaching, sharing, and community; I&#039;m surprised you write &#039;crappy&#039;. Guess I must be an idealist too...&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>keepITCool: on a site dedicated to teaching, sharing, and community; I&#8217;m surprised you write &#8216;crappy&#8217;. Guess I must be an idealist too&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dick Kusleika</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/06/16/reading-xml-files-in-vba/#comment-39964</link>
		<dc:creator>Dick Kusleika</dc:creator>
		<pubDate>Sun, 21 Jun 2009 00:57:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=2591#comment-39964</guid>
		<description>&lt;p&gt;You&#039;re surprised I write crappy code?  You must be some kind of idealist.&lt;/p&gt;
&lt;p&gt;I thought I had to use a Variant for Split.  That&#039;s a new one on me.  As for writing to cells in a loop, I never do that when it counts - I swear.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>You&#8217;re surprised I write crappy code?  You must be some kind of idealist.</p>
<p>I thought I had to use a Variant for Split.  That&#8217;s a new one on me.  As for writing to cells in a loop, I never do that when it counts &#8211; I swear.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: keepITcool</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/06/16/reading-xml-files-in-vba/#comment-39945</link>
		<dc:creator>keepITcool</dc:creator>
		<pubDate>Sat, 20 Jun 2009 07:10:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=2591#comment-39945</guid>
		<description>&lt;p&gt;Dick,&lt;br&gt;
As pointed out by others your use of XML has room for improvement. But on a site dedicated to Excel I&#039;m amazed that you (and others) still write crappy code. &lt;/p&gt;
&lt;p&gt;IMHO Variants are only used when there&#039;s no alternative, code should run for non US separators and I never pump data to a sheet on a cell by cell basis. Following code does the same as yours, but is tidy. Example is latebound, so a reference to XML 3 or 6 is not needed.&lt;/p&gt;
&lt;div style=&quot;overflow: auto; white-space: nowrap;&quot; class=&quot;codecolorer-container vb default&quot;&gt;&lt;div style=&quot;white-space: nowrap;&quot; class=&quot;vb codecolorer&quot;&gt;&lt;span class=&quot;kw1&quot;&gt;Sub&lt;/span&gt; ReadStateXML()&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; adList() &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Double&lt;/span&gt;&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; asText() &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;String&lt;/span&gt;&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; sFile &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;String&lt;/span&gt;&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; sXpath &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;String&lt;/span&gt;&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; i &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Long&lt;/span&gt;&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; j &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Long&lt;/span&gt;&lt;br&gt;
&#160; &lt;br&gt;
&#160; sFile = &lt;span class=&quot;st0&quot;&gt;&quot;C:UsersxxxDocuments1198.kml&quot;&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
&#160; &lt;span class=&quot;co1&quot;&gt;&#039;Reminder: XML is caseSensitive!&lt;br&gt;
&lt;/span&gt; &#160;sXpath = &lt;span class=&quot;st0&quot;&gt;&quot;//Placemark/MultiGeometry/Point/coordinates&quot;&lt;/span&gt;&lt;br&gt;
&#160; &lt;br&gt;
&#160; &lt;span class=&quot;kw1&quot;&gt;With&lt;/span&gt; CreateObject(&lt;span class=&quot;st0&quot;&gt;&quot;MSXML2.DOMDocument&quot;&lt;/span&gt;)&lt;br&gt;
&#160; &#160; Debug.Assert Len(Dir(sFile)) &lt;span class=&quot;co1&quot;&gt;&#039;Check the file exists&lt;br&gt;
&lt;/span&gt; &#160; &#160;.Load sFile&lt;br&gt;
&#160; &#160; Debug.Assert .parseError.errorCode = 0&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;With&lt;/span&gt; .documentElement.selectNodes(sXpath)&lt;br&gt;
&#160; &#160; &#160; Debug.Assert .Length&lt;br&gt;
&#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;ReDim&lt;/span&gt; adList(.Length - 1, 1)&lt;br&gt;
&#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;For&lt;/span&gt; i = 0 &lt;span class=&quot;kw1&quot;&gt;To&lt;/span&gt; .Length - 1&lt;br&gt;
&#160; &#160; &#160; &#160; asText = Split(.Item(i).Text, &lt;span class=&quot;st0&quot;&gt;&quot;,&quot;&lt;/span&gt;)&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;For&lt;/span&gt; j = 0 &lt;span class=&quot;kw1&quot;&gt;To&lt;/span&gt; 1&lt;br&gt;
&#160; &#160; &#160; &#160; &#160; &lt;span class=&quot;co1&quot;&gt;&#039;Use Val not Cstr&lt;br&gt;
&lt;/span&gt; &#160; &#160; &#160; &#160; &#160;adList(i, j) = Val(asText(j))&lt;br&gt;
&#160; &#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Next&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Next&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; Range(&lt;span class=&quot;st0&quot;&gt;&quot;A2&quot;&lt;/span&gt;).Resize(.Length, 2) = adList&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;With&lt;/span&gt;&lt;br&gt;
&#160; &lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;With&lt;/span&gt;&lt;br&gt;
&#160; &lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Sub&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;
</description>
		<content:encoded><![CDATA[<p>Dick,<br />
As pointed out by others your use of XML has room for improvement. But on a site dedicated to Excel I&#8217;m amazed that you (and others) still write crappy code. </p>
<p>IMHO Variants are only used when there&#8217;s no alternative, code should run for non US separators and I never pump data to a sheet on a cell by cell basis. Following code does the same as yours, but is tidy. Example is latebound, so a reference to XML 3 or 6 is not needed.</p>
<div style="overflow: auto; white-space: nowrap;" class="codecolorer-container vb default">
<div style="white-space: nowrap;" class="vb codecolorer"><span class="kw1">Sub</span> ReadStateXML()<br />
<span class="kw1">Dim</span> adList() <span class="kw1">As</span> <span class="kw1">Double</span><br />
<span class="kw1">Dim</span> asText() <span class="kw1">As</span> <span class="kw1">String</span><br />
<span class="kw1">Dim</span> sFile <span class="kw1">As</span> <span class="kw1">String</span><br />
<span class="kw1">Dim</span> sXpath <span class="kw1">As</span> <span class="kw1">String</span><br />
<span class="kw1">Dim</span> i <span class="kw1">As</span> <span class="kw1">Long</span><br />
<span class="kw1">Dim</span> j <span class="kw1">As</span> <span class="kw1">Long</span><br />
&nbsp; <br />
&nbsp; sFile = <span class="st0">&#8220;C:UsersxxxDocuments1198.kml&#8221;</span></p>
<p>&nbsp; <span class="co1">&#8216;Reminder: XML is caseSensitive!<br />
</span> &nbsp;sXpath = <span class="st0">&#8220;//Placemark/MultiGeometry/Point/coordinates&#8221;</span><br />
&nbsp; <br />
&nbsp; <span class="kw1">With</span> CreateObject(<span class="st0">&#8220;MSXML2.DOMDocument&#8221;</span>)<br />
&nbsp; &nbsp; Debug.Assert Len(Dir(sFile)) <span class="co1">&#8216;Check the file exists<br />
</span> &nbsp; &nbsp;.Load sFile<br />
&nbsp; &nbsp; Debug.Assert .parseError.errorCode = 0<br />
&nbsp; &nbsp; <span class="kw1">With</span> .documentElement.selectNodes(sXpath)<br />
&nbsp; &nbsp; &nbsp; Debug.Assert .Length<br />
&nbsp; &nbsp; &nbsp; <span class="kw1">ReDim</span> adList(.Length &#8211; 1, 1)<br />
&nbsp; &nbsp; &nbsp; <span class="kw1">For</span> i = 0 <span class="kw1">To</span> .Length &#8211; 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; asText = Split(.Item(i).Text, <span class="st0">&#8220;,&#8221;</span>)<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">For</span> j = 0 <span class="kw1">To</span> 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">&#8216;Use Val not Cstr<br />
</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;adList(i, j) = Val(asText(j))<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">Next</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">Next</span><br />
&nbsp; &nbsp; &nbsp; Range(<span class="st0">&#8220;A2&#8243;</span>).Resize(.Length, 2) = adList<br />
&nbsp; &nbsp; <span class="kw1">End</span> <span class="kw1">With</span><br />
&nbsp; <span class="kw1">End</span> <span class="kw1">With</span><br />
&nbsp; <br />
<span class="kw1">End</span> <span class="kw1">Sub</span></div>
</div>
]]></content:encoded>
	</item>
</channel>
</rss>

