이것이 재 게시임을 알고 있지만 LINQ를 사용할 수 없어서 필요했습니다 (이전 게시물에서 요청 됨)..net 2.0 C# XML에서 값 가져 오기
아래의 XML 문서에서 woeid를 읽어야합니다. yahoo 기상 서비스를 쿼리 할 수 있도록 문자열 변수에 데이터를 읽고 저장해야합니다. 쿼리에 의해 반환
XML :
<query yahoo:count="1"
yahoo:created="2009-12-22T08:30:31Z"
yahoo:lang="en-US"
yahoo:updated="2009-12-22T08:30:31Z"
yahoo:uri="http://query.yahooapis.com/v1/yql?q=select+woeid+from+geo.places+where+text%3D%22farnborough%2C+greater+london%2Cuk%22">
<diagnostics>
<publiclyCallable>true</publiclyCallable>
<url execution-time="32">
http://where.yahooapis.com/v1/places.q(farnborough%2C%20greater%20london%2Cuk);start=0;count=10
</url>
<user-time>33</user-time>
<service-time>32</service-time>
<build-version>4265</build-version>
</diagnostics>
<results>
<place>
<woeid>19941</woeid>
</place>
</results>
</query>
누군가가 내가 XPath는 또는 .net 2.0의 라이브러리와 호환되는 다른 방법을 통해이 작업을 수행 할 수있는 방법을 제안 할 수 있습니다?
답변 해 주셔서 감사합니다. 따라서 나는 아래의 방법을 사용하고,하지만 난 XML 문서를로드 할 때 발생 예외가 얻을 :
private string getWOEID(string UserLocation, string UserCountry)
{
string woeID = "";
if (UserLocation == "farnborough") { UserLocation = "farnborough" + "%2C" + "hampshire"; }
String reqUrl = "http://query.yahooapis.com/v1/public/yql?q=select%20woeid%20from%20geo.places%20where%20text%3D%22" + UserLocation + "%2C" + UserCountry + "%22&format=xml";
XmlDocument doc = new XmlDocument();
doc.LoadXml(reqUrl);
string woeid = doc.SelectSingleNode("query/results/place/woeid/text()").Value;
return woeID;
}
수정 사항에 대한 업데이트 답변을 참조하십시오. – ChaosPandion
고마워 ChaosPandion 나는 수정으로 재건. 그러나 예외는 여전히 doc.LoadXml (reqUrl) 문에서 발생합니다. { "1 단계, 위치 1의 루트 수준의 데이터가 유효하지 않습니다."} – van
필요에 맞게 내 대답을 업데이트했습니다. LoadXml을 Load로 바꿨습니다. – ChaosPandion