c# - SelectSingleNode to Evaluate LowerCase NodeSet value -


i trying value of xpath expression in lower case using selectsinglenode, there xpath can give me lower case value of evaluated xpath expression?

it possible having xsl transform sheet, possible below?

the function expects have nodeset type, below evaluates string throws exception. possible convert returning string nodeset make selectsinglenode happy

        string xml = "<bac><test>val</test></bac>";         string xpath = "/bac/test/text()";          var transpath = "translate(/bac/test/text(),'abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz')";          stringreader sreader = new stringreader(xml);          xmlreader xreader = new xmltextreader(sreader);                     xpathdocument xmlpathdoc = new xpathdocument(xreader);         xpathnavigator nav = xmlpathdoc.createnavigator();          xpathnodeiterator nodeiterator = nav.select("/");          xpathnavigator navnode = nodeiterator.current;         var v = navnode.selectsinglenode(transpath).value;        // expect val  

if have xpath expression returns primitive value (string, number, boolean) instead of set of nodes need use evaluate method on xpathnavigator, see http://msdn.microsoft.com/en-us/library/2c16b7x8.aspx.

so code simplify to

    string xml = "<bac><test>val</test></bac>";     string xpath = "/bac/test";      var transpath = "translate(/bac/test,'abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz')";       xpathnavigator nav;      using (stringreader sr = new stringreader(xml))      {         nav = new xpathdocument(sr).createnavigator();      }      string v = nav.evaluate(transpath) string; 

on other hand .net stronger on string operations xpath 1.0 tempted use

 xpathnavigator test = nav.selectsinglenode(path);  string v = test.value.tolower(); 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -