The GW-Scripting list is a discussion list for information regarding the development and use of Window-Eyes scripts. Any subscriber of the GW-Scripting list has the ability to post on-topic messages.

From:

 "BX" <bronx_lab@fltg.net>

Subject:

 Re: Writing Data To An XML - I am stuck...

Date:

 Thu, Apr 4, 2013 9:24:10 am
This is a multi-part message in MIME format.

------=_NextPart_000_0006_01CE3116.2A07F850
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi Dave!

When I read it I also thought the same thing as Chip, just did not have time to respond. For .ini have blocks which are sectioned out by name and if something new comes in it comes in under the block name already made. If no section key exists it makes a new one and adds it to the end...
The only difference is that XML is more universal, .ini requires Windoweyes installed...


Bruce

Sent: Thursday, April 04, 2013 7:11 AM
Subject: RE: Writing Data To An XML - I am stuck...


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:trailerdavid@hotmail.com]
Sent: Wednesday, April 03, 2013 12:17 PM
To: gw-scripting@gwmicro.com
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.

------=_NextPart_000_0006_01CE3116.2A07F850
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML xmlns="http://www.w3.org/TR/REC-html40"; xmlns:v =
"urn:schemas-microsoft-com:vml" xmlns:o =
"urn:schemas-microsoft-com:office:office" xmlns:w =
"urn:schemas-microsoft-com:office:word" xmlns:m =
"http://schemas.microsoft.com/office/2004/12/omml"><HEAD>;
<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 8.00.6001.19403">
<STYLE>@font-face {
font-family: Calibri;
}
@font-face {
font-family: Tahoma;
}
@page WordSection1 {size: 8.5in 11.0in; margin: 1.0in 1.0in 1.0in 1.0in; }
P.MsoNormal {
MARGIN: 0in 0in 0pt; FONT-FAMILY: "Times New Roman","serif"; FONT-SIZE: 12pt
}
LI.MsoNormal {
MARGIN: 0in 0in 0pt; FONT-FAMILY: "Times New Roman","serif"; FONT-SIZE: 12pt
}
DIV.MsoNormal {
MARGIN: 0in 0in 0pt; FONT-FAMILY: "Times New Roman","serif"; FONT-SIZE: 12pt
}
A:link {
COLOR: blue; TEXT-DECORATION: underline; mso-style-priority: 99
}
SPAN.MsoHyperlink {
COLOR: blue; TEXT-DECORATION: underline; mso-style-priority: 99
}
A:visited {
COLOR: purple; TEXT-DECORATION: underline; mso-style-priority: 99
}
SPAN.MsoHyperlinkFollowed {
COLOR: purple; TEXT-DECORATION: underline; mso-style-priority: 99
}
SPAN.EmailStyle17 {
FONT-FAMILY: "Calibri","sans-serif"; COLOR: #1f497d; mso-style-type: personal-reply
}
..MsoChpDefault {
FONT-SIZE: 10pt; mso-style-type: export-only
}
DIV.WordSection1 {
page: WordSection1
}
</STYLE>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></HEAD>
<BODY lang=EN-US link=blue bgColor=white vLink=purple>
<DIV><FONT size=2 face=Arial>Hi Dave!</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial>&nbsp;&nbsp;&nbsp; When I read it I also thought
the same thing as Chip, just did not have time to respond. For .ini have blocks
which are sectioned out by name and if something new comes in it comes in under
the block name already made. If no section key exists it makes a new one and
adds it to the end...</FONT></DIV>
<DIV><FONT size=2 face=Arial>&nbsp;&nbsp;&nbsp; The only difference is that XML
is more universal, .ini requires Windoweyes installed...</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial>&nbsp;&nbsp;&nbsp; Bruce</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<BLOCKQUOTE
style="BORDER-LEFT: #000000 2px solid; PADDING-LEFT: 5px; PADDING-RIGHT: 0px; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px"
dir=ltr>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Thursday, April 04, 2013 7:11
AM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> RE: Writing Data To An XML - I
am stuck...</DIV>
<DIV><FONT size=2 face=Arial></FONT><FONT size=2 face=Arial></FONT><BR></DIV>
<DIV class=WordSection1>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt">Hi
David,<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt">I
wrote to you directly from my work address, but it may not have made it as I
didn’t hear back.<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt">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.&nbsp; 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.<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt">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.<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt">Hth,<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt">Chip<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt"><o:p>&nbsp;</o:p></SPAN></P>
<DIV>
<DIV
style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 0in; PADDING-RIGHT: 0in; BORDER-TOP: #b5c4df 1pt solid; BORDER-RIGHT: medium none; PADDING-TOP: 3pt">
<P class=MsoNormal><B><SPAN
style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt">From:</SPAN></B><SPAN
style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"> David
[mailto:trailerdavid@hotmail.com] <BR><B>Sent:</B> Wednesday, April 03, 2013
12:17 PM<BR><B>To:</B> gw-scripting@gwmicro.com<BR><B>Subject:</B> Writing
Data To An XML - I am stuck...<o:p></o:p></SPAN></P></DIV></DIV>
<P class=MsoNormal><o:p>&nbsp;</o:p></P>
<DIV>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt">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.</SPAN><o:p></o:p></P></DIV>
<DIV>
<P class=MsoNormal>&nbsp;<o:p></o:p></P></DIV>
<DIV>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt">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.</SPAN><o:p></o:p></P></DIV>
<DIV>
<P class=MsoNormal>&nbsp;<o:p></o:p></P></DIV>
<DIV>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt">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.</SPAN><o:p></o:p></P></DIV>
<DIV>
<P class=MsoNormal>&nbsp;<o:p></o:p></P></DIV>
<DIV>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt">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? :)</SPAN><o:p></o:p></P></DIV>
<DIV>
<P class=MsoNormal>&nbsp;<o:p></o:p></P></DIV>
<DIV>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt">Sub
RegisterProduct( ProductSection, ProductName)<BR>&nbsp;Dim
ProductRegistryFilename: ProductRegistryFilename =
ClientInformation.ScriptPath &amp;"ProductList.xml"<BR>&nbsp;Dim ProductXML:
Set ProductXML = CreateObject(
"MSXML2.DOMDocument.6.0")<BR>&nbsp;ProductXml.preserveWhiteSpace =
True</SPAN><o:p></o:p></P></DIV>
<DIV>
<P class=MsoNormal>&nbsp;<o:p></o:p></P></DIV>
<DIV>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt">&nbsp;ProductXML.Load(
ProductRegistryFilename)</SPAN><o:p></o:p></P></DIV>
<DIV>
<P class=MsoNormal>&nbsp;<o:p></o:p></P></DIV>
<DIV>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt">&nbsp;Dim DocElem :
Set DocElem = ProductXML.documentElement<BR>&nbsp;If DocElem Is Nothing
Then<BR>&nbsp;&nbsp;ProductXML.LoadXML(
"&lt;Products&gt;&lt;/Products&gt;")<BR>&nbsp;&nbsp;Dim pi : Set pi =
ProductXML.createProcessingInstruction("xml",
"version='1.0'")<BR>&nbsp;&nbsp;ProductXML.insertBefore pi,
ProductXML.documentElement<BR>&nbsp;End If 'DocElem Is
Nothing.</SPAN><o:p></o:p></P></DIV>
<DIV>
<P class=MsoNormal>&nbsp;<o:p></o:p></P></DIV>
<DIV>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt">&nbsp;Dim Kind: Set
Kind = ProductXML.CreateElement(
ProductSection)<BR>&nbsp;ProductXML.DocumentElement.AppendChild
Kind</SPAN><o:p></o:p></P></DIV>
<DIV>
<P class=MsoNormal>&nbsp;<o:p></o:p></P></DIV>
<DIV>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt">' Product
name:<BR>&nbsp;Dim Name: Set Name = ProductXML.CreateElement(
"Name")<BR>&nbsp;Name.Text = Productname<BR>&nbsp;Kind.AppendChild
Name</SPAN><o:p></o:p></P></DIV>
<DIV>
<P class=MsoNormal>&nbsp;<o:p></o:p></P></DIV>
<DIV>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt">' Save the Product
Registration Card to the XML registry:<BR>&nbsp;ProductXML.Save
ProductRegistryFilename</SPAN><o:p></o:p></P></DIV>
<DIV>
<P class=MsoNormal>&nbsp;<o:p></o:p></P></DIV>
<DIV>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt">'
Room-cleaning:<BR>&nbsp;If Not ProductXML Is Nothing Then&nbsp;Set ProductXML
= Nothing<BR>&nbsp;If Not Kind Is Nothing Then&nbsp;Set Kind =
Nothing<BR>&nbsp;If Not Name Is Nothing Then&nbsp;Set Name = Nothing<BR>End
Sub 'RegisterProduct.</SPAN><o:p></o:p></P></DIV>
<DIV>
<P class=MsoNormal>&nbsp;<o:p></o:p></P></DIV>
<DIV>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt"><BR>If now, I call
this sub with the following lines:<o:p></o:p></SPAN></P></DIV>
<DIV>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt">&nbsp;<o:p></o:p></SPAN></P></DIV>
<DIV>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt">RegisterProduct
"Computer", "HP"<BR>RegisterProduct "Computer", "Dell"<BR>RegisterProduct
"Printer", "Canon"<o:p></o:p></SPAN></P></DIV>
<DIV>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt">&nbsp;<o:p></o:p></SPAN></P></DIV>
<DIV>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt">The resulting XML
file, will look like this:<o:p></o:p></SPAN></P></DIV>
<DIV>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt">&nbsp;<o:p></o:p></SPAN></P></DIV>
<DIV>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt">&lt;Products&gt;<BR>&nbsp;&lt;Computer&gt;<BR>&nbsp;&nbsp;&lt;Name&gt;HP&lt;/Name&gt;<BR>&nbsp;&lt;/Computer&gt;<BR>&nbsp;&lt;Computer&gt;<BR>&nbsp;&nbsp;&lt;Name&gt;Dell&lt;/Name&gt;<BR>&nbsp;&lt;/Computer&gt;<BR>&nbsp;&lt;Printer&gt;<BR>&nbsp;&nbsp;&lt;Name&gt;Cannon&lt;/Name&gt;<BR>&nbsp;&lt;/Printer&gt;<BR>&lt;/Products&gt;<o:p></o:p></SPAN></P></DIV>
<DIV>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt">&nbsp;<o:p></o:p></SPAN></P></DIV>
<DIV>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt">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:<o:p></o:p></SPAN></P></DIV>
<DIV>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt">&nbsp;<o:p></o:p></SPAN></P></DIV>
<DIV>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt">&nbsp;&lt;Computer&gt;<BR>&nbsp;&nbsp;&lt;Name&gt;HP&lt;/Name&gt;<BR>&nbsp;&nbsp;&lt;Name&gt;Dell&lt;/Name&gt;<BR>&nbsp;&lt;/Computer&gt;<o:p></o:p></SPAN></P></DIV>
<DIV>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt">&nbsp;<o:p></o:p></SPAN></P></DIV>
<DIV>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt">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? :)
<o:p></o:p></SPAN></P></DIV>
<DIV>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt">&nbsp;<o:p></o:p></SPAN></P></DIV>
<DIV>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt">As always, thanks
for any feedback.</SPAN><o:p></o:p></P></DIV></DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0006_01CE3116.2A07F850--