Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / July 2003

Tip: Looking for answers? Try searching our database.

performance problem with SelectSingleNode

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John R. - 02 Jul 2003 12:50 GMT
I have an application written in C# and i am using MS XML
DOM!

I have a document with the following structure (only the  
<DicEntry> - Elements are important):

<NewDataSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance">
 .
 <DicEntry TextKey="Test1" KeyDependency="True">
   <default>Test1</default>
   <de>Button Germanmanuell</de>
   <it />
 </DicEntry>
 <DicEntry TextKey="Dialog1" KeyDependency="True">
   <default>Dialog1</default>
   <de />
   <it />
 </DicEntry>
 .
</NewDataSet>

I now want to merge such a document with a document of
type XmlDataDocument with the same structure in memory!

There is the main code:

XmlElement root = this.DictionaryDocument.DocumentElement;
//bei Formbezogene "TextKey" = "default"

ls = @"/*/DicEntry[@TextKey=" +
TTUtility.GetXPathConcatParamList(this.TextKey) + "]
[@KeyDependency=" + TTUtility.GetXPathConcatParamList
(this.CurrentMergeNode.Attributes.GetNamedItem
("KeyDependency").Value.ToString()) + "]/*[name()=" +
TTUtility.GetXPathConcatParamList(mNode.Name) + "]";

lNode = root.SelectSingleNode(ls);

The method GetXPathConcatParamList builds a parameterlist
for the Xpath method concat.

/// <summary>
   /// this method builds a parameterlist for the Xpath
method concat,
   /// so that the method SelectSingleNode can also work
(search) on
   /// elements, attributes with double quotation marks
in their names.
   /// </summary>
   /// <param name="aValue">a string</param>
   /// <returns>concat condition for SelectSingleNode
method</returns>
   public static string GetXPathConcatParamList(string
aValue)
   {
     char[] lSplit = new char[1] {'"'};
     string[] lSplitValues={""};
     int lSplitValuesLen;
     string lReturn="";
     string lValue="";
     string lHelp="";

     //replace &quot; in aValue with "
     lValue = aValue.Replace("&quot;", "\"");

     //split with "
     lSplitValues = lValue.Split(lSplit);
     lSplitValuesLen = lSplitValues.Length;
     //if there is no double quotation mark then return
     //and there is no build for concat
     if(lSplitValuesLen == 1)
     {
       lReturn = "\"" + aValue + "\"";
     }
     else //build parameterlist for method concat
     {
       for (int i = 0; i <= lSplitValuesLen - 1; i++)
       {
         if(i==lSplitValuesLen - 1)
           lHelp = lHelp + "\"" + lSplitValues[i] + "\"";
         else
           lHelp = lHelp + "\"" + lSplitValues[i] + "\""
+ "," + "'\"'" + ",";
       }
       lReturn = "concat(" + lHelp + ")";
     }
     return lReturn;
   }

Performance results:

Merging   10 <DicEntry> - Elements into       100      in
memory =>     ca.     1 sec.
Merging   10 <DicEntry> - Elements into       500      in
memory =>     ca.     6 sec.
Merging   10 <DicEntry> - Elements into     1000      in
memory =>     ca.     12 sec.
Merging  100 <DicEntry> - Elements into       100      in
memory =>     ca.     21 sec.
Merging  100 <DicEntry> - Elements into     1000      in
memory =>     ca.   190 sec.
Merging 1000 <DicEntry> - Elements into     1000      in
memory =>     ca.   over 3600 sec.

The method "SelectSingleNode" takes time of 96 % of the
applications running time!!!!!!!!!!!!!!!!!!!!!

Please can you help on this problem?

thanks,
john
Christoph Schittko [MVP] - 04 Jul 2003 06:00 GMT
Where are you using XmlDataDocument? It is not obvious from your code.
Anyway, XmlDataDocument is not nearly as performance optimized as an
XPathDocument for example. Have you tried reading the Xml from the DataSet
into an XPath doc or a regular XmlDocument to do the merge?

Signature

HTH
Christoph Schittko [MVP]
Software Architect, .NET Mentor

> I have an application written in C# and i am using MS XML
> DOM!
[quoted text clipped - 108 lines]
> thanks,
> john
John R. - 04 Jul 2003 08:31 GMT
I have XML data in a XmlDataDocument and i want to merge
them into another existing XmlDataDocument.
I have to insert and update data in the existing
XmlDataDocument.

In my code this.DictionaryDocument is of type
XmlDataDocument (the existing one).

I am using XmlDataDocument because i have a GUI where i
present the resulting data and a grid where i can bind the
dataset property of the XmlDataDocument!

with the code fragment:
"XmlElement root =
this.DictionaryDocument.DocumentElement;              
ls = @"/*/DicEntry[@TextKey=" +
TTUtility.GetXPathConcatParamList(this.TextKey) + "]
[@KeyDependency=" + TTUtility.GetXPathConcatParamList
(this.CurrentMergeNode.Attributes.GetNamedItem
("KeyDependency").Value.ToString()) + "]/*[name()=" +
TTUtility.GetXPathConcatParamList(mNode.Name) + "]";
lNode = root.SelectSingleNode(ls);"

...i get the node in the existing XmlDataDocument that i
want to update (before i testet if there is one!)

thanks,
John

>-----Original Message-----
>Where are you using XmlDataDocument? It is not obvious from your code.
[quoted text clipped - 116 lines]
>
>.
Oleg Tkachenko - 06 Jul 2003 11:20 GMT
> I have XML data in a XmlDataDocument and i want to merge
> them into another existing XmlDataDocument.
> I have to insert and update data in the existing
> XmlDataDocument.

Obviously you can get better XPath expression evaluation performance using
XPathDocument instead, which is specially optimized for that. But you cannot
update XPathDocument, because it's read-only by definition.
Also you can try to simplify your XPath expression.
Signature

Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.