Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML Syntax for Node Objects ? 1

Status
Not open for further replies.

Docpro777

Programmer
Joined
Jul 1, 2003
Messages
105
Location
US
I'm very new at XML:

I'm trying to convert these 2 lines (from MS Outlook terms) into VFP terms to make a node object (B):

A) --objXML = New MSXML2.DOMDocument--
B) --objXMLNode = MSXML2.IXMLDOMNode--

I believe the 1st VFP conversion is:
A) --objXML=CREATEOBJECT("MSXML2.DomDocument")--
B)

That leaves (B). Can any of you thoughtful XML'ers help me convert (B) --objXMLNode = MSXML2.IXMLDOMNode-- into VFP (COM) Syntax?

Thanks in advance.

Philip M. Traynor, DPM
 
DocPro777

Here is a piece of code I suggested to a "french newsgroup" recently that listsinstalled software on a PC into an XML format that may shed some light on XML . It uses the most likely installed "Microsoft.XMLDOM" on most systems.
Code:
#Define ERROR_SUCCESS       0
#Define KEY_ALL_ACCESS      0xF003F
#Define HKEY_CURRENT_USER   0x80000001
#Define HKEY_LOCAL_MACHINE  0x80000002
#Define HKEY_USERS          0x80000003

#Define REG_SZ        1
#Define REG_EXPAND_SZ 2
#Define REG_BINARY    3
#Define REG_DWORD     4
#Define REG_MULTI_SZ  7

Do loadAPICalls

Local oReg
oReg = Createobject("Tregister", 
HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVers
ion\Uninstall")

If Type("oReg") = "O"
	oReg.SaveToFile("c:\temp\reg.xml")
Endif
Define Class Tregister As Custom
	oXml=.F.
	Procedure Init(hParentKey, cSubkey)
	Local hKey, oXml, oKey
	hKey = 0
	If RegOpenKeyEx(hParentKey, cSubkey, 0, 
KEY_ALL_ACCESS, @hKey) <> ERROR_SUCCESS
		Return .F.
	Endif
	This.oXml = Createobject(&quot;Microsoft.XMLDOM&quot;)
	This.oXml.LoadXML(&quot;<&quot; + &quot;Registry/&quot; + &quot;>&quot;)
	With This.oXml.documentElement()
		.SetAttribute(&quot;name&quot;, cSubkey)
		.SetAttribute(&quot;parent&quot;, hParentKey)
	Endwith
	oKey = Createobject(&quot;Tkey&quot;, This.oXml, 
This.oXml.documentElement(), hKey)
	Procedure SaveToFile(cFilename)
	If File(cFilename)
		Delete File(cFilename)
	Endif
	This.oXml.Save(cFilename)
	= ShellExecute(0,&quot;open&quot;, cFilename, &quot;&quot;, &quot;&quot;, 3)
Enddefine
Define Class Tkey As Custom
	oXml=.F.
	parentnode=.F.
	hKey=0
	Procedure Init(oXml, oParentNode, hKey)
	This.oXml = oXml
	This.parentnode = oParentNode
	This.hKey = hKey
	This.EnumValues
	This.EnumSubKeys
	= RegCloseKey(This.hKey)
	Procedure EnumValues
	Local nIndex, nNameLen, nDataLen, nType, cName, 
cData, objProperty
	nIndex = 0
	Do While .T.
		Store 4096 To nNameLen, nDataLen
		Store Repli(Chr(0), nDataLen) To cName, 
cData
		nType = 0
		If RegEnumValue(This.hKey, nIndex, @cName, 
@nNameLen,;
				0, @nType, @cData, 
@nDataLen) <> ERROR_SUCCESS
			Exit
		Endif
		cName = Substr(cName, 1, At(Chr(0),cName)-
1)
		cData = Substr(cData, 1, At(Chr(0),cData)-
1)
		If Not Empty(cName)
			objProperty = 
This.oXml.CreateElement(&quot;Value&quot;)
			objProperty.SetAttribute(&quot;name&quot;, 
cName)
			objProperty.SetAttribute(&quot;type&quot;, 
nType)
			If nType = REG_DWORD
				cData = buf2dword(Padr
(cData,4,Chr(0)))
			Endif
			objProperty.SetAttribute(&quot;Data&quot;, 
cData)
			This.parentnode.AppendChild
(objProperty)
		Endif
		nIndex = nIndex + 1
	Enddo
	Procedure EnumSubKeys
	Local nIndex, cBuffer, nResult, hKey, objSubnode, 
oKey
	nIndex = 0
	Do While .T.
		cBuffer = Repli(Chr(0), 512)
		nResult = RegEnumKey(This.hKey, nIndex, 
@cBuffer, Len(cBuffer))
		If nResult <> ERROR_SUCCESS
			Exit
		Endif
		cBuffer = Substr(cBuffer, 1, At(Chr
(0),cBuffer)-1)
		hKey = 0
		If RegOpenKeyEx(This.hKey, cBuffer, 0, 
KEY_ALL_ACCESS, @hKey) = ERROR_SUCCESS
			objSubnode = 
This.oXml.CreateElement(&quot;Key&quot;)
			objSubnode.SetAttribute(&quot;name&quot;, 
cBuffer)
			This.parentnode.AppendChild
(objSubnode)
			oKey = Createobject(&quot;Tkey&quot;, 
This.oXml, objSubnode, hKey)
		Endif
		nIndex = nIndex + 1
	Enddo
Enddefine
Procedure loadApiCalls
Declare Integer RegEnumKey In advapi32;
	INTEGER hKey, Integer dwIndex, String @lpName,;
	INTEGER cchName
Declare Integer RegOpenKeyEx In advapi32;
	INTEGER hKey, String lpSubKey, Integer ulOptions,;
	INTEGER samDesired, Integer @phkResult
Declare Integer RegEnumValue In advapi32;
	INTEGER hKey, Integer dwIndex, String 
@lpValueName,;
	INTEGER @lpcValueName, Integer lpReserved, Integer 
@lpType,;
	STRING @lpData, Integer @lpcbData
Declare Integer ShellExecute In shell32;
	INTEGER HWnd, String lpOperation, String lpFile,;
	STRING lpParams, String lpDir, Integer nShowCmd
Declare Integer RegCloseKey In advapi32 Integer hKey
Function buf2dword(lcBuffer)
Return Asc(Substr(lcBuffer, 1,1)) + ;
	BitLShift(Asc(Substr(lcBuffer, 2,1)),  8) +;
	BitLShift(Asc(Substr(lcBuffer, 3,1)), 16) +;
	BitLShift(Asc(Substr(lcBuffer, 4,1)), 24)


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Mike, I took your general advice about using the XML parser to create custom Outlook views and repeatedly studied:
1) MSDN Library's VBA and XML examples under Outlook 2002
2) Outlook Help file examples
3) Fox Advisor's limited examples of XML and Outlook per se.
4) COM: Createobject(&quot;MSXML2.DomDocument&quot;) ... anywhere it could be Googled.
5) Etc.

Finally, after days of mental strivings (prayers) and trial and error failures, my prayers were answered and the code became manifested. This has been the sequence:

1) First, generate an appropriate custom table view manually in Outlook, modify it in Outlook to suit your special custom view needs.

2) Create an XML file generator.prg; copy the following code with Outlook OPEN, i.e.,:

#Define olFolderCalendar 9
objView = CreateView(&quot;New Calendar Table View&quot;,olFolderCalendar,0)
***
Function CreateView
Parameters strName,cnstFolderName,cnstViewType
PUBLIC objViews as Views
PUBLIC objViewCalendar as View
oOutlook = Createobject(&quot;Outlook.Application&quot;)
objXML=Createobject(&quot;MSXML2.DomDocument&quot;)

objViews = oOutlook.getnamespace(&quot;MAPI&quot;).GetDefaultFolder(cnstFolderName).Views

For Each objView In objViews
If objView.Name=strName
?objView.name
=STRTOFILE(objView.XML,'MyXMLfile') &&the XML suffix generates the XML code (see XML under VBA properties)
Endif
Endfor

3. Voila/hallelulia: You've just created your custom Outlook table view in XML that EVEN INCLUDES YOUR USER DEFINED FIELDS repleat with properties, format(s), etc. in XML.
Note: USER DEFINED FIELDS are practically impossible to write in XML directly. Check out what MS Outlook generated in XML for MyUserDefinedField User Defined Field:
<column>
<heading>MyUserDefinedField</heading>
<prop> <type>boolean</type>
<width>36</width>
<style>text-align:center;padding-left:3px</style>
<format>boolicon</format>
<displayformat>3</displayformat>
</column>

4. Next, Open the (temporary) MyXMLfile itself and copy (to the clipboard) all the XML code that was generated by outlook ...via VFP's STRTOFILE(objView.XML,'MyXMLfile') statement. Open/label an XML file (notepad) of your choosing: In this example you might label that file &quot;objViewCalendar.XML&quot;

5. Then, make another program and copy this code into it:
#DEFINE olTableView 0
=SetTableProperties(&quot;New Calendar Table View&quot;) &&This parameter name is arbitrary
****
FUNCTION SetTableProperties
PARAMETERS strViewName
PUBLIC objViews as Views
PUBLIC objViewCalendar as View
oOutlook = Createobject(&quot;Outlook.Application&quot;)
objXML=Createobject(&quot;MSXML2.DomDocument&quot;)

objViews = oOutlook.GetNamespace(&quot;MAPI&quot;).GetDefaultFolder(9).Views &&InBox
objViewCalendar = objViews.ADD(strViewName,olTableView,0)

objXML.load(&quot;objViewCalendar.XML&quot;)
objViewCalendar.XML = objXML.XML &&MUST KEEP THIS

objViewCalendar.Save
objViewCalendar.Apply

It is finished. Now just tie up any loose ends and integrate it into your COM object(s) and application.

Now that I'm 'dangerously aquainted' with XML, Microsoft.XMLDOM, Outlook's XML property, etc., I must thank you wholeheartedly for prodding me into discovering this most viable and excellent solution for programtically creating the custom Outlook view(s) in VFP.

I'm looking forward to studying your &quot;french newsgroup&quot; code and probing further ideas.

In the meantime I hope other users might exploit Outlook's vast potential with the above sequences.

Philip M. Traynor, DPM
 
Philip M. Traynor

I'm glad that I was able to point out in the direction of your solution. Thank you for the star.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top