2017-08-17 12 views
0

私はXMLのように持っていると仮定します。私は私が望むようにデバッグするとき、私の変数に「テスト」を市と風のための情報を見ることができるが、私は残りのためのブランクを得る読むXMLコンテンツ

<current> 
    <city id="2563232" name="London"> 
    <coord lon="-0.13" lat="51.51"> 
    <country>GB</country> 
    <sun rise="2017-08-17T04:23:00" set="2017-08-17T17:48:39"/> 
    </city> 
    <temperature value="305.15" min="305.15" max="305.15" unit="kelvin"/> 
    <humidity value="25" unit="%"/> 
    <pressure value="1015" unit="hPa"/> 
    <wind>...</wind> 
    <clouds value="0" name="clear sky"/> 
    <visibility value="10000"/> 
</current> 

を。私のコード:

XmlNodeList xnlNodes = OtherClass.retrieveXMLResponse(respStream); 
String test = ""; 

foreach (XmlNode xndNode in xnlNodes) 
{ 
    test = xndNode["city"].InnerXml; 
    test = xndNode["wind"].InnerXml; 
    test = xndNode["temperature"].InnerXml; 
    test = xndNode["humidity"].InnerXml; 
    test = xndNode["pressure"].InnerXml; 
    test = xndNode["clouds"].InnerXml; 
    test = xndNode["visibility"].InnerXml; 
} 

"test"を後でオブジェクトに置き換えます。ただ属性を含むノードには内部XMLはありません

public static XmlNodeList retrieveXMLResponse(Stream stream) 
{ 
    StreamReader reader = new StreamReader(stream, Encoding.UTF8); 
    string responseString = reader.ReadToEnd(); 
    XmlDocument xmlDoc = new XmlDocument(); 
    xmlDoc.LoadXml(responseString); 

    XmlElement xelRoot = xmlDoc.DocumentElement; 
    XmlNodeList xnlNodes = xelRoot.SelectNodes("/current"); 

    return xnlNodes; 
} 
+2

他のタグは自己閉鎖です。だから、彼らの中には何もない。あなたはInnerXMLを呼び出すことで何を期待しますか? – litelite

答えて

3

、これInnerXmlプロパティプロパティは空白である:これはretrieveXMLResponse方法です。特定のノードの属性値を読み取る場合は、各XMLノードにattributesプロパティがあります。

+0

私はそれを見なかったと信じている!ありがとう、私が必要とするすべてのgetAttribute。 – Dragonfly