【发布时间】:2012-03-08 15:29:36
【问题描述】:
我无法加载 Xdocument.Load 我无法加载 Xdocument.Load我无法加载 Xdocument.Load我无法加载 Xdocument.Load我无法加载 Xdocument.Load我无法加载 Xdocument.Load我无法加载加载 Xdocument.Load我无法加载 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。
【问题讨论】:
-
有什么理由使用
XmlTextReader而不是(比如说)LINQ to XML? (您还应该考虑将大代码分解为更小的方法,更改缩进样式,并使用 StringBuilder 而不是字符串连接。) -
我不知道如何使用 linq,这就是我使用 XMLTEXTReader 的原因。我将其更改为字符串生成器而不是串联。
-
我认为@JonSkeet 的意思是,您不妨重写整个内容。 :)
-
@SmilingLily:使用 LINQ to XML 会更简单。哎呀,使用
XmlDocument会更简单,但是 LINQ to XML 让它变得轻而易举。 -
你知道我可以改变什么来打印与磁贴相关的作者姓名吗?
标签: c# asp.net xml xmltextwriter xmltextreader