Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / October 2003

Tip: Looking for answers? Try searching our database.

XML Parsing in c#

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Filip Kratochvil - 22 Oct 2003 22:44 GMT
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]
>   }
> =======================================================================

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.