XML get value of td cell using XPath expression

Im attempting to get td cell values within a table cell without a name/id from a table row using an XPath expression but haven't been able to resolve it. Could readers let me know where Im wrong?

        XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.Load("C:\\trial.html");

    XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);
    nsmgr.AddNamespace("ns", "http://www.w3.org/1999/xhtml");

    XmlNode root = xmlDoc.DocumentElement;
    System.Xml.XmlNodeList rowNodes = root.SelectNodes(@"ns:body/ns:div[@id='Index']/ns:div[@class='container']/ns:div[@class='maintext']/ns:table[@class='a_table']/ns:tr[@class='a_table_row']", nsmgr);

    foreach (XmlNode xmlNode in rowNodes)
    {
        // Is there a way to get nodes with td values(non-empty)? My attempts
        // seem to be wrong
        //System.Xml.XmlNodeList tds = xmlNode.SelectNodes("//td[text()]", nsmgr);
        //System.Xml.XmlNodeList tds = xmlNode.SelectNodes("//td[contains(text(), .)]", nsmgr);
        if (xmlNode.ChildNodes.Count == 3)
            nodes.Add(xmlNode);

    }

Answers


With your code I think you want to use

XmlNodeList tds = xmlNode.SelectNodes("ns:td[normalize-space()]", nsmgr);

to find any non-empty td child elements of the tr selected as xmlNode.


Need Your Help

How to get value (draft.DraftId = new int();)and use in the variable

asp.net linq

In my aspx page I have a dropdownlist when I select value "Draft Document" it gets new DraftID (identity).

iOS url response bool

ios objective-c nsurlconnection nshttpurlresponse

net web service that returns true or false but i don't know how to catch that response in my IOS App.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.