아래 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>
여기에 표 (즉, 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을 반환한다.
편집 : 내가 코드 아래 사용 : 문자열 반응 = 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있어?
미리 감사드립니다.
감사합니다. 이제 나는 aaa와 bbb 태그의 값을 얻을 수 있습니다. 하지만 여기서는 ListBox.ItemsSource에 바인딩하고 싶습니다. 어떻게하면 돼? ListBox에 아래와 같은 텍스트 상자가 있지만 데이터가 바인딩되지 않습니다. " " –
Avinash