Hello all,
I would like to replicate the following VB code in c# but having problems
with the ancestor, could someone please suggest what I need to do here.
I need to get the information - tag name - of the parent as specified in the
second XPath statement
Thanks in advance
Filip
VB Code:
=======================================================================
strUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
strLower = "abcdefghijklmnopqrstuvwxyz"
strXPath = "//name[contains(translate(.,'" & strUpper & "','" & strLower &
"'),'" & LCase(Trim(txtSearch.Text)) & "')]"
Set oXml = New MSXML2.DOMDocument40
oXml.async = False
oXml.Load txtDataFile.Text
oXml.setProperty "SelectionLanguage", "XPath"
Set oNodeList = oXml.selectNodes(strXPath)
For Each oNode In oNodeList
Set oParent = oNode.selectSingleNode("ancestor::*[last()-1]")
If Not oParent Is Nothing Then
txtResult.Text = txtResult.Text & oParent.nodeName & " - " &
oNode.Text & vbCrLf
End If
Next
=======================================================================
So far in C#
=======================================================================
private void btnSearch_Click(object sender, System.EventArgs e)
{
if (txtSearch.Text!="")
{
string strUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string strLower = "abcdefghijklmnopqrstuvwxyz";
string strLookup = txtSearch.Text;
strLookup.Trim();
strLookup.ToLower();
XPathDocument myXPathDocument = new XPathDocument(lblDataFile.Text);
XPathNavigator myXPathNavigator = myXPathDocument.CreateNavigator();
XPathQuery(myXPathNavigator, "//name[contains(translate(.,'" + strUpper
+ "','" + strLower + "'),'" + strLookup + "')]");
}
}
private void XPathQuery(XPathNavigator myXPathNavigator, String
xpathexpr )
{
try
{
XPathNodeIterator myXPathNodeIterator = myXPathNavigator.Select
(xpathexpr);
while (myXPathNodeIterator.MoveNext())
{
txtResult.Text += myXPathNodeIterator.Current.Value + "\n";
// here I want to get my ancestor details as well
}
}
catch (Exception e)
{
//Console.WriteLine ("Exception: {0}", e.ToString());
}
}
=======================================================================
SQL Server Development Team - 23 Oct 2003 01:46 GMT
Use the XmlDocument not the XPathDocument if you want to program against the
DOM

Signature
This posting is provided "AS IS" with no warranties, and confers no rights.
> Hello all,
>
[quoted text clipped - 70 lines]
> }
> =======================================================================