Use Linq in javascript

Sep 26, 2011 at 2:07 AM

The following code works in C#, but error was thrown if run it as javascript under JInt.

var xmlRoot = System.Xml.Linq.XElement.Load("D:\\Temp\\Test.xml");
var userName = xmlRoot.Element("UserName");

The error is:

Invalid cast from 'System.String' to 'System.Xml.Linq.XName'.

The problem is that XName does not have an public constructor.

Anybody know how to modify the above statement and make it run?

Sep 26, 2011 at 7:55 PM
Edited Sep 26, 2011 at 7:55 PM

Try using XName.Get static method to create a XName object from a string