469,625 Members | 1,089 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,625 developers. It's quick & easy.

performance problem with SelectSingleNode

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">
Nov 11 '05 #1
3 5768
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?

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

"John R." <rj@hcdv.at> wrote in message
news:10****************************@phx.gbl...
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

Nov 11 '05 #2
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.Anyway, XmlDataDocument is not nearly as performance optimized as anXPathDocument for example. Have you tried reading the Xml from the DataSetinto an XPath doc or a regular XmlDocument to do the merge?
--
HTH
Christoph Schittko [MVP]
Software Architect, .NET Mentor

"John R." <rj@hcdv.at> wrote in message
news:10****************************@phx.gbl...
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 " in aValue with "
lValue = aValue.Replace(""", "\"");

//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

.

Nov 11 '05 #3
John R. wrote:
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.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by gordon.lear | last post: by
2 posts views Thread by Edward Yang | last post: by
4 posts views Thread by Paul M | last post: by
7 posts views Thread by Sharon | last post: by
1 post views Thread by mjwills | last post: by
3 posts views Thread by christopher.davidson | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.