如何阅读XML Child
本文关键字:Child XML 何阅读 | 更新日期: 2023-09-27 18:17:34
从XML中读取凭据令牌作为字符串的最佳方法是什么?
<?xml version="1.0" encoding="UTF-8"?>
<tsResponse xmlns="http://tableausoftware.com/api" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tableausoftware.com/api http://tableausoftware.com/api/ts-api-2.0.xsd">
<credentials token="090834586395787390244234">
<site contentUrl="GPS_Test"/>
</credentials>
</tsResponse>
Many Thanks
尝试一下,但是"最好的方法"总是因人而异的…
XDocument doc = XDocument.Parse(youXmlString);
var value = doc.SelectSingleNode("/credentials").Attribute("token").Value;
我用下面的代码算出来了。
XDocument document = XDocument.Parse(responseFromServer);
var value = document.Descendants().Single(i => i.Attribute("token") != null)
.Attribute("token").Value;