Click here to Skip to main content
15,889,651 members
Home / Discussions / Algorithms
   

Algorithms

 
GeneralRe: Solutions distribution of the N-Queens problem Pin
Richard MacCutchan12-Oct-17 22:05
mveRichard MacCutchan12-Oct-17 22:05 
QuestionNeed to display dialog until all questions answered Pin
Christopher Cote11-Oct-17 3:24
Christopher Cote11-Oct-17 3:24 
AnswerRe: Need to display dialog until all questions answered Pin
Sascha Lefèvre11-Oct-17 4:01
professionalSascha Lefèvre11-Oct-17 4:01 
AnswerRe: Need to display dialog until all questions answered Pin
Jochen Arndt11-Oct-17 4:07
professionalJochen Arndt11-Oct-17 4:07 
QuestionSorting Algorithm to maximize 'availability' (help please) Pin
Member 134476015-Oct-17 3:30
Member 134476015-Oct-17 3:30 
AnswerRe: Sorting Algorithm to maximize 'availability' (help please) Pin
Ralf Meier6-Oct-17 0:35
mveRalf Meier6-Oct-17 0:35 
AnswerRe: Sorting Algorithm to maximize 'availability' (help please) Pin
Gerry Schmitz7-Oct-17 6:41
mveGerry Schmitz7-Oct-17 6:41 
QuestionEfficiently comparing results from an XPath query to a resultset returned from a database table Pin
terrybogard44-Oct-17 14:49
terrybogard44-Oct-17 14:49 
Hi,
Let's say, I have an XML file that looks like this.

<donors>
<donor>
<donorid>1
<name>abc
<amount>$50


<donor>
....



and I have a table that looks like this:

Relation Name
-------------

Donor

Columns
-------

DonorID - bigint
DonorName - nvarchar(100)
DonationCeiling - float

I want to get all of the donor names and amounts from the xml and compare them against the maximum amount allowed. I want to remove all donors from the xml whose donation has exceed the ceiling.

I can do this.

XmlNamespaceManager nsmanager = new XmlNamespaceManager(reader.NameTable);
nsmanager.AddNamespace("donor", "www.mydomain.com/xmlns/donor");
nsmanager.PushScope();

XmlDocument doc = new XmlDocument();
doc.Load("donors.xml");

//Select and display the value of all the ISBN attributes.
XmlNodeList donorIds;
XmlNodeList donationAmount ;

XmlElement root = doc.DocumentElement;
nodeList = root.SelectNodes("/donors/donorid", nsmanager);

Is there a way to retrieve all xml node values from two different xml nodes using one xml path expression into one data structure. For instance, get all donor Ids an donation amount as a key-value list in one data-structure making a single call to root.SelectNodes

Once the donation ids and donations amounts are retrieved, even if they are retrieved as two separate XmlNodeLists, what is the most efficient way to compare these values to the DonationCeiling values returned from the Donor table.

The select query to the Donor table would look like this:

string sql = "Select DonorID, DonationCeiling from Donor where DonorID in ('" + (why can't we just pass the whole XmlNodeList as one data-structure here, without having to loop-through and build the list of DonorId's from the XMLNodeList + "') ;

recordset.ExecuteSQL(sql) ;

After the sql returns the recordset, is there an efficient way to compare the DonationAmounts in the XmlNodeList to the DonationCeiling amounts returned from the Donor table without having two nested loops.

int donorId = Convert.ToInt32(donorIds[0].InnerText) ;

while (!recordset.EOF) {
for (int i=0; i < donorIds.Count;i++) {
if (Convert.ToInt32(donationAmount[i].InnerText) > recordSet.Fields("donationCeiling").Value (should not have to cast to string and then to an integer - the compiler should automatically determine the type based on the returned value from the database column) {
// remove donor node from xml file
}
}
}

Is there a way to do the above without two loops?

Thanks for the time you might spend trying to figure this out. If you can't, that is ok, I have not figured it out so far. Maybe, there is no other way.

Thanks,



Saad
AnswerRe: Efficiently comparing results from an XPath query to a resultset returned from a database table Pin
Gerry Schmitz7-Oct-17 6:57
mveGerry Schmitz7-Oct-17 6:57 
QuestionConditional assembly Pin
A Jordison27-Sep-17 23:53
A Jordison27-Sep-17 23:53 
AnswerRe: Conditional assembly Pin
Jochen Arndt28-Sep-17 0:09
professionalJochen Arndt28-Sep-17 0:09 
GeneralRe: Conditional assembly Pin
A Jordison28-Sep-17 0:13
A Jordison28-Sep-17 0:13 
GeneralRe: Conditional assembly Pin
Jochen Arndt28-Sep-17 0:20
professionalJochen Arndt28-Sep-17 0:20 
AnswerRe: Conditional assembly Pin
Gerry Schmitz28-Sep-17 10:33
mveGerry Schmitz28-Sep-17 10:33 
QuestionCompare similarity of values that can have different lenght, number of words between 2 or more documents. Pin
Member 1342117220-Sep-17 21:46
Member 1342117220-Sep-17 21:46 
AnswerRe: Compare similarity of values that can have different lenght, number of words between 2 or more documents. Pin
Gerry Schmitz21-Sep-17 12:49
mveGerry Schmitz21-Sep-17 12:49 
QuestionEfficiently sort the following? Pin
arnold_w24-Aug-17 10:18
arnold_w24-Aug-17 10:18 
GeneralRe: Efficiently sort the following? Pin
harold aptroot24-Aug-17 10:28
harold aptroot24-Aug-17 10:28 
GeneralRe: Efficiently sort the following? Pin
arnold_w24-Aug-17 10:48
arnold_w24-Aug-17 10:48 
AnswerRe: Efficiently sort the following? Pin
Richard MacCutchan24-Aug-17 21:05
mveRichard MacCutchan24-Aug-17 21:05 
AnswerRe: Efficiently sort the following? Pin
Richard Deeming25-Aug-17 1:47
mveRichard Deeming25-Aug-17 1:47 
GeneralRe: Efficiently sort the following? Pin
arnold_w28-Aug-17 0:40
arnold_w28-Aug-17 0:40 
GeneralRe: Efficiently sort the following? Pin
Richard Deeming29-Aug-17 1:53
mveRichard Deeming29-Aug-17 1:53 
GeneralRe: Efficiently sort the following? Pin
arnold_w30-Aug-17 4:04
arnold_w30-Aug-17 4:04 
GeneralRe: Efficiently sort the following? Pin
Richard Deeming30-Aug-17 4:40
mveRichard Deeming30-Aug-17 4:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.