Monday, September 27, 2010
Web Dev Network Growth, XML and Road to GeoRSS
The Web Dev Network is growing fast. I created this group on July 1, 2010 and we have members on six continents in eight countries. The Web Dev Network's most recent online meeting's topic was about XML. I am starting a companion post to the last meeting which will lead up to October's meeting about GeoRSS. The companion post will be a re-cap of the online meeting that we had on September 24, 2010.
First we are goinng to start with a very basic block of XML. This block of XML code has three items that make it so that it does have some value.
<?xml version="1.0" encoding="utf-8"?>
<rootElement>
<docElement>Add your content here.</docElement>
</rootElement>
The first line is the XML declaration. It is the first required piece of a well-formed XML document. The second line displays a tag named rootElement. This is the root element of the XML document. All XML documents must have a root element. The root element is basically a container for the rest of your document. The third line is a child element. The child element is where your content of your XML document will. That's if for this now. We will build extend this example in my next post as we continue to build our way to GeoRSS.
Now, as I said, here is a basic example to automate the creation of this document using HTA for a graphical user interface and VBScript.
All you have to do is copy the code into a text editor and save the file as createXml.hta.
Now, if you are not sure how to do this, please comment. My postings will be geared to providing working code and I won't provide step by step instructions, but if the need is there I can back up and help out.
Copy on next line:
<!DOCTYPE html Public "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!--
'********************************************************************************
'*
'* HTA Name: createXml.hta
'* Author: Chris Sergent
'* Created: 10/5/2010
'* Description: This HTA dynamically creates an xml skeleton document.
'*
'********************************************************************************
'* HTA DOCUMENTATION
'*
'* Any HTA changes will be documented here with date, change and author.
'*
'********************************************************************************
'*Graphical User Interface Section
'********************************************************************************
-->
<head>
<!-- Application Name is the name of the HTA application that would appear in
Windows Task Manager. -->
<!-- Properties that can be set.
- Border Type of window borders
Define the border as thick for a resizable border
Define the border as thin for a non-resizable window
-WindowState Default state is normal out of the three possible,
(Normal, Minimize, Maximize)
For the following properties, use the value yes to display and the value no,
to not display. All defaults for these properties are yes.
-Caption
-MaximizeButton
-MinimizeButton
-Scroll
-ShowInTaskbar
-SingleInstance Specifies if multiple instances are allowed to run
-SysMenu Determines if the application will display the System menu
-->
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>HTA XML Skeleton Creator</title><!-- Caption To display On title bar -->
<!--
'********************************************************************************
'*
'* SETTINGS FOR HTA
'*
'********************************************************************************
-->
<!-- Although HTA has defaults, I have entered the defaults in manually, so you
can see the syntax and change them as you see fit. The settings are divided
into two groups, required or optional. The required information is either a
must have or something that might be very noticeable if you ignore.
-->
<HTA:APPLICATION>
<!-- Required -->
APPLICATIONNAME="Resume Creator"
SCROLL="yes"
SINGLEINSTANCE="yes"
WINDOWSTATE="maximize"
<!-- Optional -->
Border = "thick" <!-- No default -->
Caption = "yes"
MaximizeButton = "yes"
MinimizeButton = "yes"
ShowInTaskbar = "yes"
SysMenu = "yes"
</HTA:APPLICATION>
</head>
<script language="VBScript">
'************************************************************************************
'*
'* Script Name: Scripts are Object Oriented and are named in each sub.
'* Author: Chris Sergent
'* Created: 11/8/2007
'* Description: This script is a starter template for writing scripts in HTA.
'* As usual, I have added information that appears to be found
'* frequently in various authored scripts eliminating the need to
'* re-type this.
'*
'************************************************************************************
'* DOCUMENTATION
'*
'* Any script changes will be documented here with date, change and author.
'*
'* 1/23/2009
'* This script now generates a complete web page with head, title, meta, paragraph,
'* and body elements.
'*
'************************************************************************************
'* Initialization Section
'************************************************************************************
Option Explicit
'************************************************************************************
'* Declare Constants
'************************************************************************************
Const ForAppending = 8 'Allows for adding information to a file
Const ForWriting = 2 'Writes to a file(writes over existing file as well)
Const ForReading = 1 'Reads a file
'************************************************************************************
'* Define Variables
'************************************************************************************
'Path Variables
Dim strTemplate 'Template File Location
Dim strDocument 'Documenting the Log File
'WMI Variables
Dim objWMIService, objOSItem, objCSItem
Dim colCSItems
Dim strComputer
strComputer = "."
Dim strUserName
strUserName = "HKCU\Software\Microsoft\Windows\" &_
"CurrentVersion\Explorer\Logon User Name"
'FSO Variables
Dim objFSO 'File System Object
Dim objFile 'File Object
Dim objTSO 'Temporary System Object
Dim objFolder 'Folder Object
objFolder = "C:\Templates\"
'Window Variables
Dim intLeft, intTop, inthorizontal, intVertical
'GUI Objects
Dim strTemplateName 'Path of Template
Dim txtTemplateName
Dim txtTitle
Dim txtHead
'************************************************************************************
'* Set the Values for the Variables
'************************************************************************************
'Set up an instance of the WshShell object
'Common Variable Values
'WMI Values
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colCSItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem")
'FSO Values
Set objFSO = CreateObject("Scripting.FileSystemObject")
'************************************************************************************
'* Main Processing Section
'************************************************************************************
'Events
Sub Window_Onload
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colCSItems = objWMIService.ExecQuery("Select * From Win32_DesktopMonitor")
For Each objOSItem in colCSItems
intHorizontal = objOSItem.ScreenWidth
intVertical = objOSItem.ScreenHeight
Next
intLeft = (intHorizontal - 800) / 2
intTop = (intVertical - 600) / 2
End Sub
'Check to see if a template already exists. The application will not overwrite
'an existing template with the same name.
Sub CreateTemplate
TemplateCheck()
End Sub
'************************************************************************************
'* Procedure Section
'************************************************************************************
Function TemplateCheck()
strTemplate = objFolder & txtTemplateOutput.value
Msgbox strTemplate
If objFSO.FileExists(strTemplate) Then
Msgbox "Document Exists"
Exit Function
Else
If Not objFSO.FolderExists(objFolder) Then
objFSO.CreateFolder(objFolder)
End If
strTemplate = objFolder & txtTemplateOutput.value
objFSO.CreateTextFile(strTemplate)
Set objFile = objFSO.OpenTextFile(strTemplate, ForWriting)
objFile.WriteLine "<?xml version=" & """1.0""" & " encoding=" & """utf-8""" & "?>" & vbcrlf & _
"<rootElement>" & vbcrlf & _
"<docElement>" & vbcrlf & _
"Add your content here." & vbcrlf & _
"</" & "docElement>" & vbcrlf & _
"</rootElement>"
objFile.Close()
MsgBox strTemplate & " Created"
End If
End Function
</script>
<!--
'************************************************************************************
'* HTA GUI Section
'************************************************************************************
-->
<body>
Enter a title (Example:skeleton.xml)<br />
<input id="txtTemplateName" type="text" value="skeleton.xml" name="txtTemplateOutput" style="width: 336px"/><br />
<br />
<input type="button" value="Create Template" name="run_button" onClick="CreateTemplate">
<p>
<span id = "DataArea"></span>
</p>
</body>
</html>
<!--
'************************************************************************************
'* Nothing To See Here - Please Move Along
'************************************************************************************
-->
Don't copy this line or any after this one.
Later this week, we will finish the XML document and start an XSD. Next up, I will add a Python example that creates the same XML file. This may seem simple now, but we will be building on this in multiple languages, scripting and code.
Do you have any cool code you would like to share with us?
Labels:
HTA,
online collaboration,
programming GIS,
ProNetwork,
VBScript
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment
I have had the opportunity to share this with you and I encourage you to share your comments with me.