Can Strategies include classes from System.Xml?
Author: haytac
Creation Date: 4/11/2012 8:04 PM
profile picture

haytac

#1
Hi,
Can Wealth Lab Strategies include classes that come with System.Xml?
Thanks!
profile picture

Eugene

#2
Absolutely. Example: Example 2 - Downloading the LIBOR rate data from an XML-based datasource

In this case, don't forget to add a reference to the System.Xml namespace (Editor > References...)
profile picture

haytac

#3
Thanks, that worked. I was adding "using System.Xml" to the top of the file under other using statements. That gave a compile error. I wonder what is the difference?
profile picture

Eugene

#4
The difference is that the C# project (which your Strategy is too) is missing a reference to the assembly where the System.Xml namespace "lives in". By default, Wealth-Lab adds references to System, Windows.Forms (and maybe something else) transparently to the user, making it possible to include the using directives that you see in the default Strategy template.
profile picture

haytac

#5
Getting to using the Xml reference. Where can I insert the following line:
"XmlDocument CommonFile = null;"?

I checked the box: System.Xml in Editor > References.

- Inside namespace WealthLab.Strategies? error: CS0116, a namespace does not directly contain members such as fields or methods
- Inside public class MyStrategy : WealthScript? CS0246: The type or namespace name 'XmlDocument' could not be found (are you missing a using directive or an assembly reference?)
- Inside protected override void Execute()? same error

In all 3 cases 'XmlDocument' was not recognized and highlighted in blue.

Thanks

profile picture

Eugene

#6
Take a careful look at the link above that contains a working example of XmlDocument usage.
profile picture

haytac

#7
Thanks, careful was the word.
In addition to checking the Xml box in editor > references, one must also add the line "using System.Xml" in the strategy file.
profile picture

Eugene

#8
I should've highlighted it, but having taken a look at your post above (4/12/2012 12:34 AM) where you said it was included, reconsidered.
profile picture

rajeshu

#9
Sorry to bring old thread to life but I am facing issue in addling System.Xml

In the strategy editor I did select System.Xml in References... > .NET and clicked Ok but while adding Sysatem.Xml its giving the error that Xml does not exist in the namespace System. Is there any lib file I need to download and update somewhere?
profile picture

Eugene

#10
You forgot to click OK or clicked Cancel in References.
profile picture

rajeshu

#11
I clicked OK, I also tried others like System.Transactions just to see but they are also showing same error.
profile picture

Eugene

#12
Cannot reproduce in 6.9.23, NET 4.8. Could you attach a screenshot with using statements, checked References, and the compiler error?
profile picture

rajeshu

#13
Please find attached the screenshots, its still work in progress code.
profile picture

Eugene

#14
Your code is missing using System.Linq. Maybe using System.Xml.Linq too - you'll find it answered in Microsoft Docs or Stackoverflow. That will fix it.

P.S. As for WLD5Issue.png, this is a non-issue: Squiggly red lines when referencing external libraries
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).