【发布时间】:2021-08-07 10:52:52
【问题描述】:
请问如何获取此 XML 中元素 StatusCode 的属性值:
<LogoutResponse
ID="_f525259e-7e91-4282-9dc3-a0da65a4a17a"
Version="2.0"
IssueInstant="2021-05-17T15:41:55Z"
InResponseTo="_5089729f-5cc0-4a66-a3c1-e710cde92897"
Destination="https://idp.xyz/logout.aspx"
xmlns="urn:oasis:names:tc:SAML:2.0:protocol">
<Issuer xmlns="urn:oasis:names:tc:SAML:2.0:assertion">https://abc.xyz/api</Issuer>
<Status>
<StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success" />
</Status>
</LogoutResponse>
【问题讨论】:
-
处理XML的API有多种;你用的是哪个?你试过什么?例如,你看过
XDocument吗?或者XmlDocument(这是一个完全独立的API来做同样的事情),或者XmlSerializer? -
这能回答你的问题吗? Getting attribute using XPath
-
@MarcGravell 任何
XDocument或XmlDocument。但是名称空间有些东西,我不知道如何正确编写代码。请查看@Krishna Muppalla 代码现在可以工作,我不知道为什么。