Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 9th, 2008, 01:34 AM
Registered User
 
Join Date: Aug 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Performance issue while forming a tree for 10 MB X

Hi,

I added Infragistics.Win.UltraWinTree.UltraTree Control to the form. Added root nodes in the nodes properties (collection) of that control. Example: Tariff Data -> Time Band List

In the Form Load event I wrote code to form a Tree for 10 MB XMl File. Code follows and also giving sample xml file. You can make that xml file as much big just by copiing time band list in between Time Band List tag.

I want to be load 10 MB XML file within 1/2 minutes
Is there any other way to form tree for big XML instead of Infragistics control.

The Code in Vb.Net:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'This is the object of XMLDocument to load XML file (DOM parser)

Dim obj_TariffData_XmlDocument As New XmlDocument

'This is the object of XmlNOde to get data in between TariffData node

Dim obj_TariffData_XmlNodeTariffData As XmlNode

'This is the object of XmlNode to get all child nodes of TariffData(Root Node)

'For Example all TimeBands in the given sampe XML file. "C:\TD\TD.xml"

Dim obj_TariffData_XmlNodeTariffData_SubNode As XmlNode

'This is the object of XmlNOde to get the properties of specific node

'example: properties (data) are in between <TimeBand> Tag

' <TimeBand>

' <Name>OffPeak</Name>

' </TimeBand>

Dim obj_TariffData_XmlNodeTimeBand As XmlNode

'This is integer varibale to assign total number of Time Bands

Dim int_TariffData_NodeCountTimeBand As Integer

'This is integer variable to initialize for loop

Dim int_TariffData_LoopTimeBand As Integer

'This is the object of UltraTreeNode used to get Main root node (example Time Band List)

Dim obj_TariffData_TimeBandListNode As Infragistics.Win.UltraWinTree.UltraTreeNode

'This is the object of UltraTreeNode used to create new node and add to Main root node that is (Time Band List)

Dim obj_TariffData_TimeBandNewNode As Infragistics.Win.UltraWinTree.UltraTreeNode

'This is integer variable to get TariffData Child nodes count

Dim int_TariffData_NodeCountTariffData As Integer

'This is integer variable to intialize for loop

Dim int_TariffData_LoopTariffData As Integer

'one minute = 60 000 milliseconds

'These varibales will be used to calculate time while loading xml file.

Dim intStartTime As Long

Dim intEndTime As Long

Dim intTimeToExecute As Long

'Starts tick

intStartTime = System.Environment.TickCount

'File(Path)

Dim str_TariffData_FileName As String = "C:\TD\TD.xml"

'Open XML file using XML Document object

obj_TariffData_XmlDocument.Load(str_TariffData_Fil eName)

'To get data in between TariffData node

obj_TariffData_XmlNodeTariffData = obj_TariffData_XmlDocument.SelectSingleNode("Tarif fData")

'If Data is not nothing then

If Not obj_TariffData_XmlNodeTariffData Is Nothing Then

'Get number of child nodes of Tariff Data

int_TariffData_NodeCountTariffData = obj_TariffData_XmlNodeTariffData.ChildNodes.Count

'If child node are there then forming a tree using for loop and getting the data from XML

For int_TariffData_LoopTariffData = 0 To int_TariffData_NodeCountTariffData - 1

'Get each child node

obj_TariffData_XmlNodeTariffData_SubNode = obj_TariffData_XmlNodeTariffData.ChildNodes(int_Ta riffData_LoopTariffData)

'Checking if it is Time Band

If obj_TariffData_XmlNodeTariffData_SubNode.Name = "TimeBandList" Then

'Get Time Bands count

int_TariffData_NodeCountTimeBand = obj_TariffData_XmlNodeTariffData_SubNode.ChildNode s.Count

'If number of time bands are there then adding time band nodes into its parent node

For int_TariffData_LoopTimeBand = 0 To int_TariffData_NodeCountTimeBand - 1

'Get Time Band List tag

obj_TariffData_TimeBandListNode = Me.UTTariffData.Nodes(0).Nodes(0)

'Creating new node for new time band

obj_TariffData_TimeBandNewNode = New Infragistics.Win.UltraWinTree.UltraTreeNode

'Adding new node(new time band node) to Time Band List node

obj_TariffData_TimeBandListNode.Nodes.Add(obj_Tari ffData_TimeBandNewNode)

'assign the name of time band to that node - get the name value from time band properties

obj_TariffData_XmlNodeTimeBand = obj_TariffData_XmlNodeTariffData_SubNode.ChildNode s(int_TariffData_LoopTimeBand)

'Assigning values

If Not obj_TariffData_XmlNodeTimeBand Is Nothing Then

obj_TariffData_TimeBandNewNode.Tag = obj_TariffData_XmlNodeTimeBand.SelectSingleNode("N ame").InnerText.ToString.Replace("<", "<").Replace(">", ">").Replace("&", "&")

obj_TariffData_TimeBandNewNode.Text = obj_TariffData_XmlNodeTimeBand.SelectSingleNode("N ame").InnerText.ToString.Replace("<", "<").Replace(">", ">").Replace("&", "&")

End If

Next

End If

Next

End If

'Expanding Tree

UTTariffData.ExpandAll(ExpandAllType.Always)

'Bringing Tree into Front

UTTariffData.BringToFront()

'Showing Tree

UTTariffData.Show()

'Ends tick

intEndTime = System.Environment.TickCount

'Calaculating tickes after xml file is loaded

intTimeToExecute = intEndTime - intStartTime

'Showing message

MessageBox.Show("The total execution time to load Tariff Data in milli seconds(one minute = 60 000 milliseconds): " & intTimeToExecute)

'one minute = 60 000 milliseconds

Dim intTimeMinutesToLoadXMl As Integer = 0

intTimeMinutesToLoadXMl = intTimeToExecute / 60000

'**** message in minutes

MessageBox.Show("The total execution time to load Tariff Data in minutes(one minute = 60 000 milliseconds): " & intTimeMinutesToLoadXMl)

End Sub

Sample XML file: (Copy TimeBand tag with properties as many as to form Big XML)

<TariffData>

<TimeBandList>

<TimeBand>
      <Name>OffPeak</Name>
    </TimeBand>

</TimeBand>

</TimeBandList>

</TariffData>


Thank you for your time
Prathap Reddy U
 
Old August 9th, 2008, 02:59 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Generally in .Net you can speed up XML processing by using XPathDocument instead of XmlDocument.

Also you are doing a lot of checking for things that you really don't need to. For example you check if obj_TariffData_XmlNodeTimeBand is nothing - seeing as you have already counted the number of nodes and this is the n'th node then it wont be Nothing - in fact the previous statement would have given you a IndexOutOfBound****ception if the node didn't exist.

Also, move the following line out of the loop so it is only performed once:

Code:
obj_TariffData_TimeBandListNode = Me.UTTariffData.Nodes(0).Nodes(0)
This value is never going to change so you shouldn't be doing that inside a for loop.

Code:
InnerText.ToString.Replace("<", "<").Replace(">", ">").Replace("&", "&")
There are so many things wrong with this I don't know where to start. Firstly - InnerText is already a string, so there is NO NEED to do ToString(). Secondly you are replacing "<" with "<"? WTF?
Thirdly you repeat this same line twice - if you are going to use the result of a costly string operation twice then store it in a temporary variable - or even better just assign the .Text property to the .Tag property:

Code:
obj_TariffData_TimeBandNewNode.Text = obj_TariffData_XmlNodeTimeBand.SelectSingleNode("Name").InnerText.Replace("<", "<").Replace(">", ">").Replace("&", "&")
obj_TariffData_TimeBandNewNode.Tag = obj_TariffData_TimeBandNewNode.Text
Another thing you can do is change your SelectSingleNode("TariffData") at the start to SelectNodes("TariffData/TimeBandList") and then just loop through the node list.

Code:
obj_TariffData_TimeBandListNode = Me.UTTariffData.Nodes(0).Nodes(0)
Dim nodeList As XmlNodeList
nodeList = obj_TariffData_XmlDocument.SelectNodes("TariffData/TimeBandList/TimeBand")

For Each node As XmlNode In nodeList
    Dim newTreeNode As New Infragistics.Win.UltraWinTree.UltraTreeNode
    newTreeNode.Text = node.InnerText
    newTreeNode.Tag = newTreeNode.Text
    obj_TariffData_TimeBandListNode.Add(newTreeNode)
Next
So thats 20 lines of code down to 9 - and I hope much easier to read.

You could also try using SuspendLayout and ResumeLayout on the Tree control, and there may be other things the Tree control allows you to do that I am not aware of, but who knows.

/- Sam Judson : Wrox Technical Editor -/
 
Old August 9th, 2008, 04:06 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Since you're on a general-purpose XML forum, the chances are that only 1% of people here have ever heard of Infragistics - I certainly haven't. So if you want help with that technology, you need to look elsewhere.

As for alternatives, it's hard to say, since you haven't said anything about the requirements of the problem you are trying to solve, you've only showed a heap of Infragistics code for solving it.

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
performance issue with the xsl given here anboss XSLT 11 July 16th, 2008 03:05 AM
performance issue keyvanjan Classic ASP Basics 0 May 23rd, 2006 10:57 AM
Transactions and performance issue avanishp General .NET 0 August 25th, 2005 09:07 AM
issue of performance alyeng2000 SQL Server 2000 6 August 20th, 2004 01:17 PM
Performance issue deyakhatib SQL Server 2000 2 June 21st, 2004 10:47 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.