Member Avatar for kobalt

Hello all!
I'm very much a noob to c#... and programming for that matter... and xml! So, I'm having troubles with a project that I'm working on that I hope someone here can help me with.

I wish to search through an xml file that is generated by a Share Trading program - the search is for a particular attribute (TOOLNAME="U3RvcH==") and then I want to read the 'value' that follows (VALUES="A|0|5.31156|B|0|40129.776606555|C|0|595.96808665;A|1|5.31156|B|1|40177.8112681687|C|1|602.83018117") - this represents a horizontal line placed at [A]$5.31156 the & [C] components are the xy positions of the start and finish of the line. I am only interested in the A component of the Value.

The only constant accross any number of charts will be the TOOLNAME - so I need to search for that and then get only the 'A' portion of the Value. How do I go about this? Its got me completely stumped!

Thanks in advance!

Use XPath,

XPathDocument dc = new XPathDocument(@"file.xml");
    XPathNavigator nav = dc.CreateNavigator();

   XPathNodeIterator i = nav.Select("//WORKBOOK/PAGE/CHART/VIEW/LAYER/TOOLITEM[@TOOLNAME='U3RvcH==']");

   while (i.MoveNext()){
      string val=i.Current.GetAttribute("VALUES", "");
   }
Member Avatar for kobalt

Use XPath,

XPathDocument dc = new XPathDocument(@"file.xml");
    XPathNavigator nav = dc.CreateNavigator();

   XPathNodeIterator i = nav.Select("//WORKBOOK/PAGE/CHART/VIEW/LAYER/TOOLITEM[@TOOLNAME='U3RvcH==']");

   while (i.MoveNext()){
      string val=i.Current.GetAttribute("VALUES", "");
   }

Thanks - that worked great! I worked out that if I added:

string s = val.Substring(4, 7)

I can get the exact figure I'm after!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.