Pages

Using the XPathNavigator to Search XPathDocuments

protected void Button8_Click(object sender, EventArgs e)
{
lbl = GetLabel(275, 20);
string s;
XPathDocument xmlDoc = new XPathDocument(MapPath("iboxml.xml"));
XPathNavigator nav = xmlDoc.CreateNavigator();
string expr = "//myChild[@ChildID='ref-3']";
//Display the selection
XPathNodeIterator iterator = nav.Select(expr);
XPathNavigator navResult = iterator.Current;
while (iterator.MoveNext())
{
s = String.Format("<b>Type:</b>{0} <b>Name:</b>{1} ",navResult.NodeType, navResult.Name);
if (navResult.HasAttributes)
{
navResult.MoveToFirstAttribute();
s += "<b>Attr:</b> ";
do
{
s += String.Format("{0}={1} ",navResult.Name, navResult.Value);
}
while (navResult.MoveToNextAttribute());
}
lbl.Text += s + "<br>";
}
}

Hiç yorum yok: