Hi David,
I wrote to you directly from my work address, but it may not have made it as I didn't hear back. The problem looks to me as if you aren't checking first to see if the production section node exists before you create it and add to it. You do need to check to see if it's there, and if it is, use the existing one to add to rather than just creating a new production section node each time. The .ini file routines manage this kind of thing for you automatically, but as XML does allow for multiples of the same node name, it can't do so. Hth, Chip From: David [mailto:[email protected]] Sent: Wednesday, April 03, 2013 12:17 PM To: [email protected] Subject: Writing Data To An XML - I am stuck... I have been playing around a bit, the last few days, trying to learn the XML structure a bit more deeply. One of my projects, will need to store information in an XML registry, since that will make more tidy conditions, than would an ini file. Yes, I have done several searches on the net, mainly finding information on how to retrieve info from an XML file. I then thought of the UI design app from GW, which does update XML files frequently, when operated. Maybe I could grasp some good ideas from there, to get things going. And, yes, it sure did point me in the right direction. So far, my app does save an XML registry, and I can easily have it update the registry with new entries. Still, I am stuck on one point. I have tried to think through this one, and as I said, scrolled through the UI Design app code, hoping to grasp the meaning of what I am doing wrong. Still, cannot figure. Now I hoped, that someone of you could have a quick look, and get me on the right path. Thing is, that it keeps "multiplying" certain lines in the XML file. To illustrate it all, here follows the app code, along with the output results. Anyone see where I am lost? :) Sub RegisterProduct( ProductSection, ProductName) Dim ProductRegistryFilename: ProductRegistryFilename = ClientInformation.ScriptPath &"\ProductList.xml" Dim ProductXML: Set ProductXML = CreateObject( "MSXML2.DOMDocument.6.0") ProductXml.preserveWhiteSpace = True ProductXML.Load( ProductRegistryFilename) Dim DocElem : Set DocElem = ProductXML.documentElement If DocElem Is Nothing Then ProductXML.LoadXML( "<Products></Products>") Dim pi : Set pi = ProductXML.createProcessingInstruction("xml", "version='1.0'") ProductXML.insertBefore pi, ProductXML.documentElement End If 'DocElem Is Nothing. Dim Kind: Set Kind = ProductXML.CreateElement( ProductSection) ProductXML.DocumentElement.AppendChild Kind ' Product name: Dim Name: Set Name = ProductXML.CreateElement( "Name") Name.Text = Productname Kind.AppendChild Name ' Save the Product Registration Card to the XML registry: ProductXML.Save ProductRegistryFilename ' Room-cleaning: If Not ProductXML Is Nothing Then Set ProductXML = Nothing If Not Kind Is Nothing Then Set Kind = Nothing If Not Name Is Nothing Then Set Name = Nothing End Sub 'RegisterProduct. If now, I call this sub with the following lines: RegisterProduct "Computer", "HP" RegisterProduct "Computer", "Dell" RegisterProduct "Printer", "Canon" The resulting XML file, will look like this: <Products> <Computer> <Name>HP</Name> </Computer> <Computer> <Name>Dell</Name> </Computer> <Printer> <Name>Cannon</Name> </Printer> </Products> My big issue here is, why in the world the two entries under Computer, does produce seperate "Computer" sections. I would have expected the whole computer section of the XML, to have looked like this: <Computer> <Name>HP</Name> <Name>Dell</Name> </Computer> Obviously, I am overlooking something, and doing things the wrong way. Kind of frustrating, when you are that close, and yet cannot figure why things get stuck. Anyone out there please, who could kick me on the right track? :) As always, thanks for any feedback.
