TR wrote:
[color=blue]
> Below is a snippet of the Xml I'm trying to select. If a match is found,
> I need to use all attribs of the Node
>
> <Node>
> <Formgroups>
> <Formula MinAmt="0" MaxAmt="51" Group="0" PercentValue="0"> </Formula>
> <Formula MinAmt="51" MaxAmt="192" Group="51.00" PercentValue="10">
> </Formula>
> <Formula MinAmt="192" MaxAmt="620" Group="98.00" PercentValue="15">
> </Formula>
> <Formula MinAmt="620" MaxAmt="1409" Group="306.80"
> PercentValue="25"> </Formula>
> </Formgroups>
> </Node>[/color]
Here is one example
public static void Test (double value, string url) {
XPathDocument xmlDocument = new XPathDocument(url);
string xPathExpression =
String.Format(
CultureInfo.InvariantCulture,
"Node/Formgroups/Formula[{0} >= @MinAmt and {0} <= @MaxAmt]",
value
);
XPathNavigator xPathNavigator = xmlDocument.CreateNavigator();
XPathNodeIterator nodeIterator =
xPathNavigator.Select(xPathExpression);
while (nodeIterator.MoveNext()) {
Console.WriteLine("Found {0}, attributes are:",
nodeIterator.Current.Name);
if (nodeIterator.Current.MoveToFirstAttribute()) {
do {
Console.WriteLine("Attribute name: {0}, attribute value:
{1}", nodeIterator.Current.Name, nodeIterator.Current.Value);
}
while (nodeIterator.Current.MoveToNextAttribute());
nodeIterator.Current.MoveToParent();
}
Console.WriteLine();
}
}
you could call that as e.g.
Test(53.6, @"example.xml");
and then the output is
Found Formula, attributes are:
Attribute name: MinAmt, attribute value: 51
Attribute name: MaxAmt, attribute value: 192
Attribute name: Group, attribute value: 51.00
Attribute name: PercentValue, attribute value: 10
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/