How to modify XML files with MySQL?
Author: aykuts
Creation Date: 3/17/2014 5:40 PM
profile picture

aykuts

#1
Hi,

I am trying to write C# code that does basically the following:

- The code connects to MySql table and reads data from one MySql table (with r rows and c columns) - no issues here, everything when fine;

- The code then defines and loads one DataTable with the help MySqlDataReader - again, no issues at this stage. Code is fine;

- Each column of this datatable is in fact one strategy parameter of the strategy (i.e. each row of this datatable thus becomes `one parameter set of the strategy`.

Having said that:

- the code then loops across all of the rows of this datatable;

- the code gets the column values of each row one by one, and changes the XML elements one by one to replace old strategy values with the new ones - This is where i get the error. I cant modify the xml file from within WealthLab c# editor.

- that way, the strategy becomes configured with a new set of parameters each time;

- the code then calls runDonor and runs the strategy with given (new) set of parameters - no problem at calling runDonor as well!;

- and finally, certain statistics are recorded and inserted into one MySql table - there is no problem here as well;

**

Considering that a large chunk of this code is not related to wealthlab namespace, I coded most of the parts in Visual Studio first, compiled there using Visual Studio compiler, and seen that the code works just fine there! (i.e.the Xelement edits went just fine. I could see that the XML file is being modified after each loop when this code is run at Visual Studio!)

Then, I copied/pasted this code onto wealthscript editor, but unfortunately, the code did not compile!!.

**

The problem is at the region where I begin modifying the XML document, using ElementAt method.

More specifically, the ElementAt statement works fine at Visual Studio Editor, whereas it doesnt at Wealthlab editor.

To repeat, Despite the fact that i give reference to same DLLs and use the same `using...` statements on top of the code, Visual Studio returns no errors and runs thoroughly whereas Wealthlab returns this error:

CODE:
Please log in to see this code.



I have been googling for ages, and could not come up with any decent solution yet.

And since I dont have a programming background, I really cant figure out why the same code, that uses the same references, and the same using directives, works at Visual Studio but yield errors at Wealthlab.

At this link, one solution alternative is vowed, but frankly, it is not english to me:
http://stackoverflow.com/questions/17385774/system-xml-linq-xelement-does-not-contain-a-definition-for-first-and-no-exte



**

So, my question would be two fold:

1- How can I overcome this interesting error that is related to proper refererencing to System.Xml.Linq? Obviously, this is where the problem lies.

2- Or, lets throw this out and start from the scratch: How do you guys modify your strategy xmls? It would be splendid If I was provided a link of example codes that reads from strategy xml files, or modifies them.

(Please, help...)


For you guys to repeat the same error I also attach here the whole of the code; copy this to your editors and see if the code runs ok:




CODE:
Please log in to see this code.

profile picture

aykuts

#2
I asked the same question to another forum.

Here is the link.

http://stackoverflow.com/questions/22466438/system-xml-linq-could-not-be-referenced-properly-at-wealthlab-editor

I will let you know if a decent reply comes.

Best regards,

Aykut

profile picture

Eugene

#3
QUOTE:
Then, I copied/pasted this code onto wealthscript editor, but unfortunately, the code did not compile!!.


This is expected that the code won't compile in the current version 6.6 of Wealth-Lab's Editor. To fix that, add references to System.Core.dll and System.Xml.Linq.dll from c:\windows\microsoft.net\framework64\v4.0.30319 (64-bit WLD, or c:\windows\microsoft.net\framework\v4.0.30319 for 32-bit WLD).

In upcoming version 6.7, the Editor will get upgraded to support C#4.0 out of the box and the reference to System.Core.dll will not be required. This will make Linq statements recognized and no errors like 'no definition and no extension method ElementAt' should ever be thrown. Of course VS has no problems with that if your solution targets NET 4.0 or above.
profile picture

aykuts

#4
Thank you Eugene.

For the moment;

- I eliminated ElementAt(nE);

- and I now modify strategy parameters with this method:
XPathSelectElement("//Strategy/ParameterValues/double["+nE+"]").Value

It works just fine.

I will also configure the references as you have suggested.

**

But my problem of conflicting results (between manually run strategy net profit and runDonor result) is still there; I am familiarizing myself to this method, but frankly, I am disappointed as of now - given the time I allocated for coding vs. its benefits.

Best regards,

Aykut



This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).