Notifications
Clear all

[Closed] Dotnet TreeView and XML Conversion

 MZ1

Hi All,
I have written two Functions, Take a look at them and tell me your idea.

fn TVToXML TheTV XmlFileName = 
(
	dotNet.loadAssembly "system.xml"
	XmlDoc=dotNetObject "system.xml.xmlDocument"
	
	fn RecurseTVToXML XmlDoc TVNd XmlNd RecurseTVToXML =
	(
		NewXmlNd = XmlDoc.createElement TVNd.Name
		XmlNd.appendChild NewXmlNd
		for i=0 to TvNd.Nodes.count-1 do RecurseTVToXML XmlDoc TvNd.Nodes.Item[i] NewXmlNd RecurseTVToXML
	)
		RecurseTVToXML XmlDoc TagTV XmlDoc  RecurseTVToXML
		XmlDoc.save XmlFileName
)

fn XMLToTV XmlFileName TheTV  =
(		
	if doesFileExist XmlFileName do
	(
		dotNet.loadAssembly "system.xml"
		XmlDoc=dotNetObject "system.xml.xmlDocument"
		XmlDoc.load XmlFileName
		docEle=XmlDoc.documentElement
		
		fn RecurseXMLToTV XmlNd TVNd RecurseXMLToTV = 
		(
			for i=0 to XmlNd.childnodes.count-1 do
			(
				NewXmlNd = XmlNd.childnodes.Itemof[i]
				TagName = NewXmlNd.Name
				NewTVNd = (dotNetObject "System.Windows.Forms.TreeNode" TagName) 
				NewTVNd.name = TagName
				TVNd.nodes.add NewTVNd 
				for i=0 to NewXmlNd.childnodes.count-1 do
				(
					RecurseXMLToTV NewXmlNd NewTVNd RecurseXMLToTV
				)
			)
		)
		
		RecurseXMLToTV docEle TheTV RecurseXMLToTV
	)
)
3 Replies
 PEN

Do you have a specific question about what you have done?

1 Reply
 MZ1
(@mz1)
Joined: 11 months ago

Posts: 0

1-is it important to unload or close XML file after reading data?
2-do we had to load assembly every time in function? or we can load it at beginning of code?
my goal is to speed it up.

you’re right!
take a look at new version(XML to TV only):

fn RecurseXMLToTV XmlNd TVNd  = 
(
	for i=0 to XmlNd.childnodes.count-1 do
	(
		NewXmlNd = XmlNd.childnodes.Itemof[i]
		TagName = NewXmlNd.Name
		NewTVNd = (dotNetObject "System.Windows.Forms.TreeNode" TagName) 
		NewTVNd.name = TagName
		TVNd.nodes.add NewTVNd 
		for i=0 to NewXmlNd.childnodes.count-1 do
		(
			RecurseXMLToTV NewXmlNd NewTVNd 
		)
	)
)
	
fn XMLToTV XmlFileName TheTV  =
(		
	if doesFileExist XmlFileName do
	(
		dotNet.loadAssembly "system.xml"
		XmlDoc=dotNetObject "system.xml.xmlDocument"
		XmlDoc.load XmlFileName
		docEle=XmlDoc.documentElement
		
		RecurseXMLToTV docEle TheTV 
	)
) 

Just looking at the code I find the use of the parameters in the recurse function a bit strange. You’re passing a parameter that is named the same as the function, RecurseXMLToTV. And its value is always a pointer to the function itself. This seems pointless