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.