Parse XML using Jint

Mar 10, 2010 at 1:06 PM

Is there any way of parsing xml string with jint?

Mar 10, 2010 at 1:07 PM

Hi,

You can use the .NET XmlDocument.

Mar 10, 2010 at 1:44 PM
var doc = new System.Xml.XmlDocument();
            doc.LoadXml("<XmlRoot><Name>1</Name><Name>2</Name></XmlRoot>");
            var nodeList = doc.GetElementsByTagName("Name");

            var item

 = nodeList.Item(0);

Yup, but when you're trying to do something like:

var doc = new System.Xml.XmlDocument();

doc.LoadXml("<XmlRoot><Name>1</Name><Name>2</Name></XmlRoot>");

var nodeList = doc.GetElementsByTagName("Name");

var item  = nodeList.Item(0); <- get exception here saying System.XmlXmlElementList.Item(Int32)

 

At first i thought maybe type convertion bugged so i tryed:

var id = System.Convert.ToInt32(0); <- Object expected: ToInt32 ... but in single script line it works perfectly.

var item  = nodeList.Item(id);