"DR BILRO" <DR*****@discus sions.microsoft .com> wrote in message news:03******** *************** ***********@mic rosoft.com...
how can i get the diferent points for each interaction?
i i'm seeing the first interaction i would get access to 3 points, otherwise
i get access to two points
i can only get all the points of all interactions
What you must be doing is using the // (descendents-or-self) axis in an
XPath expression selecting all <point> elements. There's a DOM node
tree underneath, it would probably be a better approach to go to each
<interaction> element individually, and then select only it's <point>
elements.
- - - interactions.cs
using System;
using System.Xml;
public class App
{
public static void Main()
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load( "points.xml ");
XmlNode eResults = xmlDoc.Document Element;
XmlNodeList nodes = eResults.Select Nodes( "interactio n");
// Getting the atomic strings from the NameTable allows you to
// do comparisons against the names of the elements more
// efficiently.
//
string atomAuxf = xmlDoc.NameTabl e.Get( "auxf");
string atomAuxh = xmlDoc.NameTabl e.Get( "auxh");
if ( nodes != null )
{
foreach( XmlNode eInteraction in nodes )
{
XmlNodeList nodesInner = eInteraction.Se lectNodes( "point");
if ( nodesInner != null )
{
foreach( XmlNode ePoint in nodesInner )
{
// If you see NaN displayed, then the FirstChild / LastChild
// simplification may not apply and you require additional
// logic below.
//
double auxf = double.NaN, auxh = double.NaN;
XmlNode eAuxf = ePoint.FirstChi ld;
XmlNode eAuxh = ePoint.LastChil d;
// Make sure it's an Element, that it's <auxf> (or <auxh>),
// and then convert it's first child (which had better be a
// XmlTextNode) to a double.
//
if ( eAuxf.NodeType == XmlNodeType.Ele ment )
if ( eAuxf.LocalName == atomAuxf )
auxf = Convert.ToDoubl e( eAuxf.FirstChil d.Value);
if ( eAuxh.NodeType == XmlNodeType.Ele ment )
if ( eAuxh.LocalName == atomAuxh )
auxh = Convert.ToDoubl e( eAuxh.FirstChil d.Value);
Console.WriteLi ne( "Point ( auxf={0}, auxh={1} )", auxf, auxh);
}
Console.WriteLi ne( );
}
}
}
}
}
- - -
What sort of processing you want to do on these <point> elements is
entirely up to you, in this example I've just displayed them to the console
window.
I will point out that I make use of a few simplifying assumptions, namely:
1. The auxf is always the FirstChild of point.
2. The auxh is always the LastChild of point.
3. The auxf and auxh always contain a normalized XmlTextNode as their
First (only) Child that's parseable as a Double w/o causing a Format-
Exception.
In a real-world application you'll need to apply additional checks ensuring
these pre-conditions are valid. In particular, it's possible for a Comment,
for example, to exist between auxf and point and that would disrupt these
assumptions. Normally, you'll want to write code that starts with the
FirstChild and then use it's NextSibling to iterate through the child nodes
looking for the ones you want (checking if they are XmlNodeType.Ele ment
and then checking their LocalName against one of the atomized tag
names).
Derek Harmon