>source

LINQ를 사용하여 다음 XML 문서의 요소 값을 가져 오려고하는데 "개체 참조가 개체의 인스턴스로 설정되지 않았습니다.";

XML :

<soapenv:Envelope xmlns:soapenv=http://schemas.xmlsoap.org/soap/envelope/
xmlns:xsd=http://www.w3.org/2001/XMLSchema xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance>   <soapenv:Body>  <ns1:GetContactResponse soapenv:encodingStyle=http://schemas.xmlsoap.org/soap/encoding/xmlns:ns1=http://DefaultNamespace>     <GetContactReturn xsi:type="ns2:Response" xmlns:ns2=http://getContact.contact.V300>        <Contact xsi:type="ns3:Contact" xmlns:ns3=http://_contact.contact.V300>           <Address xsi:type="xsd:string">123 test</Address>           <Address2 xsi:type="xsd:string"/>           <City xsi:type="xsd:string">Los Angeles</City>           <CountryCode xsi:type="xsd:string">US</CountryCode>           <StateCode xsi:type="xsd:string">CA</StateCode>           <ZipCode xsi:type="xsd:string">90001</ZipCode>        </Contact>        <Errors soapenc:arrayType="ns4:Error[0]" xsi:type="soapenc:Array" xmlns:ns4=http://response.base.V300 xmlns:soapenc=http://schemas.xmlsoap.org/soap/encoding//>        <IsSuccessful xsi:type="xsd:boolean">true</IsSuccessful>        <RecordCount xsi:type="xsd:double">1.0</RecordCount>     </GetContactReturn>  </ns1:GetContactResponse>   </soapenv:Body> </soapenv:Envelope>

다음을 사용하여 반복합니다.

using (StreamReader rd= new StreamReader(services.GetResponseStream()))
   {
                        var ServiceResult= rd.ReadToEnd();
                        XDocument xdoc= new XDocument();
                        xdoc= XDocument.Parse(ServiceResult);
                        var xDocResult= (from x in xdoc.Descendants("Contacts")
                                          select new Location
                                          {
                                              Address= x.Element("Address").Value,
                                              Address2= x.Element("Address2").Value,
                                              city= x.Element("City").Value,
                                              statecode= x.Element("StateCode").Value,
                                              zipcode= x.Element("ZipCode").Value
                                          });
}

뿌리가 없기 때문이라고 생각합니다. 개별 요소의 값을 어떻게 얻습니까?

  • 이전 사용자 지정 크론 작업이 Wordpress에서 예약되지 않았습니다.
  • 다음 dataframe : Spark 테이블에 삽입하려고 할 때 ParseException 오류