XML Node is null in c# -


alright i'm trying information yahoo finance using yql. below code i'm using that. have tested xml location string in browser return xml code. i'm trying read code, parse , messagebox node i'm looking for. error string text null, i'm presuming because node null, because doc null. why doc null?

xmldocument doc = new xmldocument(); doc.load("https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.stocks%20where%20symbol%3d%22" + txt_symbol.text + "%22&diagnostics=true&env=store%3a%2f%2fdatatables.org%2falltableswithkeys"); xmlnode node = doc.documentelement.selectsinglenode("/results/stock/fulltimeemployees"); string text = node.innertext; 

sample response yahoo yql:

<query xmlns:yahoo="http://www.yahooapis.com/v1/base.rng" yahoo:count="1" yahoo:created="2014-06-03t21:06:06z" yahoo:lang="en-us"> <diagnostics> <url execution-start-time="0" execution-stop-time="1" execution-time="1"> <![cdata[ http://www.datatables.org/yahoo/finance/yahoo.finance.stocks.xml ]]> </url> <publiclycallable>true</publiclycallable> <cache execution-start-time="4" execution-stop-time="4" execution-time="0" method="get" type="memcached"> <![cdata[ bcd022d1d39e092a7a1390d6f5cf574a ]]> </cache> <cache execution-start-time="4" execution-stop-time="5" execution-time="1" method="get" type="memcached"> <![cdata[ 32c5f8788e8bc68ba5e635ae25257e23 ]]> </cache> <cache execution-start-time="5" execution-stop-time="6" execution-time="1" method="get" type="memcached"> <![cdata[ 8c548d6a60dd1f067626b9ecdf556eb3 ]]> </cache> <url execution-start-time="5" execution-stop-time="288" execution-time="283"> <![cdata[ http://finance.yahoo.com/q?s=ibm ]]> </url> <url execution-start-time="5" execution-stop-time="288" execution-time="283"> <![cdata[ http://finance.yahoo.com/q?s=ibm ]]> </url> <query execution-start-time="5" execution-stop-time="294" execution-time="289" params="{url=[http://finance.yahoo.com/q?s=ibm]}"> <![cdata[ select * html url=@url , xpath='//div[@id="yfi_investing_head"]/h1 | //div[@class="yfi_quote_summary"]/div[1]' ]]> </query> <url execution-start-time="5" execution-stop-time="430" execution-time="425"> <![cdata[ http://finance.yahoo.com/q/pr?s=ibm ]]> </url> <url execution-start-time="5" execution-stop-time="430" execution-time="425"> <![cdata[ http://finance.yahoo.com/q/pr?s=ibm ]]> </url> <url execution-start-time="7" execution-stop-time="455" execution-time="448"> <![cdata[ http://finance.yahoo.com/q/hp?s=ibm ]]> </url> <query execution-start-time="4" execution-stop-time="434" execution-time="430" params="{url=[http://finance.yahoo.com/q/pr?s=ibm]}"> <![cdata[ select * html url=@url , xpath='//table[@class="yfnc_datamodoutline1"]/tr/td/table/tr' limit 4 ]]> </query> <url execution-start-time="7" execution-stop-time="455" execution-time="448"> <![cdata[ http://finance.yahoo.com/q/hp?s=ibm ]]> </url> <query execution-start-time="6" execution-stop-time="461" execution-time="455" params="{url=[http://finance.yahoo.com/q/hp?s=ibm]}"> <![cdata[ select * html url=@url , xpath='//option[@selected="selected"] | //input[@maxlength="2"] | //input[@maxlength="4"]' ]]> </query> <javascript execution-start-time="3" execution-stop-time="462" execution-time="459" instructions-used="46403" table-name="yahoo.finance.stocks"/> <user-time>464</user-time> <service-time>2251</service-time> <build-version>0.2.2525</build-version> </diagnostics> <results> <stock symbol="ibm"> <companyname/> <start>1962-01-02</start> <end>2014-06-03</end> <sector>technology</sector> <industry>information technology services</industry> <fulltimeemployees>431212</fulltimeemployees> </stock> </results> </query> <!--  total: 464  --> <!--  engine4.yql.bf1.yahoo.com  --> 

doc not null. node null, however, , because xpath expression wrong.

the name of root element in xml document fetch query, xpath expression /results/stock/fulltimeemployees matches if root element has name results. there no matching nodes, selectsinglenode returns null.

try changing xpath either

/query/results/stock/fulltimeemployees 

or perhaps

//results/stock/fulltimeemployees 

(//results matches element name results @ depth in document.)


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -