c# - XML get value of td cell using XPath expression -
im attempting td cell values within table cell without name/id table row using xpath expression haven't been able resolve it. readers let me know 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) { // there way nodes td values(non-empty)? attempts // seem 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); }
with code think want use
xmlnodelist tds = xmlnode.selectnodes("ns:td[normalize-space()]", nsmgr);
to find non-empty td
child elements of tr
selected xmlnode
.
Comments
Post a Comment