2011-12-29 11 views
0

私は以下のようなXMLを持っていますが、解析できません。以下のXMLを解析するのを手伝ってください。Windows Phone 7でXML(DataSet)を解析する方法

<?xml version="1.0" encoding="utf-8"?><soap:Envelope  
xmlns:soap="http://www.w3.org/2003/05/soap-envelope"  
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body> 
<GetResponse xmlns="http://tempuri.org/"><GetResult> 
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"> 
<NewDataSet xmlns=""> 
<Table diffgr:id="Table1" msdata:rowOrder="0"> 
<a>hi1</a> 
<b>hi2</b> 
</Table> 
<Table diffgr:id="Table2" msdata:rowOrder="1"> 
<a>hi3</a> 
<b>hi4</b> 
</Table> 
</NewDataSet> 
</diffgr:diffgram> 
</GetResponse></GetResult> 
</soap:Body> 
</soap:Envelope> 

ここでは、テーブル(つまりa、b)タグの結果が必要です。私はLinqを使用してみましたが、私はそれを解析することができません。私はこのようなコードを試しました:

//XML will be there in response string 
String response = e.response; 
public static String myNamespace = "http://tempuri.org/"; 
XDocument reader = XDocument.Parse(response); 
var results = from result in reader.Descendants(XName.Get("GetResponse", myNamespace)) 
       select result.Element("GetResult"). 

しかし、このコードはnullを返しています。

EDIT: 私はコードの下に使用される: ストリング応答= e.response。だから今は、タグとタグの値を見つけることができますどのように

<NewDataSet xmlns=""> 
    <Table diffgr:id="Table1" msdata:rowOrder="0" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"> 
<a>hi1</a> 
<b>hi2</b> 
</Table> 
<Table diffgr:id="Table2" msdata:rowOrder="1" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"> 
<a>hi3</a> 
<b>hi4</b> 
</Table> 
</NewDataSet> 

public static String myNamespace = "http://tempuri.org/"; 
XDocument reader = XDocument.Parse(response); 
XElement resultElement = reader.Descendants(XName.Get("GetResult", myNamespace)).Single(); 
XElement resultElement1 = resultElement.Descendants(XName.Get("NewDataSet", "")).Single(); 

だから今resultElement1 iは、以下のようにXMLを得ましたか。

ありがとうございます。

答えて

0

要素GetResulthttp://tempuri.org名前空間にあります。したがって、select句が何も見つからないのはこのためです。

とにかく、私は次のようにクエリを単純化する:

public static String myNamespace = "http://tempuri.org/"; 
XDocument reader = XDocument.Parse(response); 
XElement resultElement = reader.Descendants(XName.Get("GetResult", myNamespace)).Single(); 
1

あなたをブロックしていますか?

あなたはこれを試すことができます応答kookizため

 var resultNewDataSet = XElement.Parse(xmlContent); 

     var result = resultNewDataSet.Descendants("Table") 
      .Select(t => new 
       { 
        aaa = t.Descendants("aaa").First().Value, 
        bbb = t.Descendants("bbb").First().Value 
       }); 

     foreach (var res in result) 
     { 
      System.Diagnostics.Debug.WriteLine("aaa: " + res.aaa + "/bbb: " + res.bbb); 
     } 
+0

感謝を。今、私はaaaとbbbタグの値を得ることができます。ここではListBox.ItemsSourceにバインドします。どうやってやるの。 ListBoxに以下のようなテキストボックスがありますが、データはバインドされていません。 "" – Avinash

関連する問題