문제

Xdocument.Load를 로드할 수 없습니다. Xdocument.Load를 로드할 수 없습니다. Xdocument.Load를 로드할 수 없습니다. Xdocument.Load를 로드할 수 없습니다. Xdocument.Load를 로드할 수 없습니다. Xdocument.Load를 로드할 수 없습니다. Xdocument를 로드할 수 없습니다. 로드Xdocument.Load를 로드할 수 없습니다.Xdocument.Load를 로드할 수 없습니다.

   public void AuthorNames(string Uri)
    {

        CredentialCache credentialCache = new CredentialCache();
        credentialCache.Add(
        new Uri("https://www.RESTWEBSERVICESSITE.com"),
        "Basic",
        new NetworkCredential("USERID", "PWD"));


        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Uri);
        request.AllowAutoRedirect = true;
        request.PreAuthenticate = true;
        request.Credentials = credentialCache;
        request.AutomaticDecompression = DecompressionMethods.GZip;

        try
        {
            using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
            {

                XmlReader responseReader = XmlReader.Create(response.GetResponseStream());

                //XmlDocument doc = new XmlDocument();

                **XDocument docs = XDocument.Load();**

               // responseReader.Read();
                //XDocument docs = XDocument.Load(response.GetResponseStream());


          List<string> books = docs.Descendants("INTEL")
          // Not really necessary, but makes it simpler
        .Select(x => new {
           Title = (string) x.Element("TITLE"),
           Author = x.Element("INTEL_AUTH")
           })
      .Select(x => new {
           Title = x.Title,
           FirstName = (string) x.Author.Element("FNAME"),
           MiddleInitial = (string) x.Author.Element("MNAME"),
           LastName = (string) x.Author.Element("LNAME"),
        })
   .Select(x => string.Format("{0}: {1} {2} {3}",
                           x.Title,
                           x.FirstName, x.MiddleInitial, x.LastName))
   .ToList();

   for (int i = 0; i < books.Count; i++)
   {
    for (int j = 0; j < books.Count; j++)
    {
    Response.Write("--" + books[i] + "---" + books[j]);
    }
   }

}

        }
        catch (Exception ex)
        {
            Response.Write("Remote server Returned an Error.");
        }
    }

XML 피드로 xdocument.Load를 로드할 수 없습니다.

도움이 되었습니까?

해결책

분명하지 않아 정확히 당신이 원하는 것은 다음과 같을 것 같습니다.

XDocument doc = ...; // However you want to load this.
// Note: XML is case-sensitive, which is one reason your code failed before
List<string> books = doc
    .Descendants("Intel")
    // Not really necessary, but makes it simpler
    .Select(x => new {
               Title = (string) x.Element("Title"),
               Author = x.Element("Intel_auth")
            })
    .Select(x => new {
               Title = x.Title,
               FirstName = (string) x.Author.Element("fname"),
               MiddleInitial = (string) x.Author.Element("mname"),
               LastName = (string) x.Author.Element("lname"),
            });
    .Select(x => string.Format("{0}: {1} {2} {3}",
                               x.Title,
                               x.FirstName, x.MiddleInitial, x.LastName))
    .ToList();

이것은 당신에게 List<string> 여기서 각 요소는 "테스트 1:존 M.pp".

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top